单条insert

 


ugc_l = browser.find_elements_by_class_name('ugc-item')

try:
myl = [{'statistics': i.text.replace('阅读', '').replace('赞', '').replace('评论', '').replace(' ⋅ ',
'').split(
'\n')[
2:5], 'url': i.find_element_by_class_name('lbtn').get_attribute('href')} for i
in
browser.find_elements_by_class_name('ugc-item')]

except Exception as e:
logs = '{}--{}'.format('myl-->', e)
print(logs)
logging.exception(logs)
continue

sql, fi = 'INSERT INTO toutiao_arcticle_museum (article_url,num_pageview,num_like,num_comment,time_museum,toutiao_uid) VALUES ', ''
for i in myl:
sql_i = '("{}","{}","{}","{}","{}","{}")'.format(
i['url'], i['statistics'][0], i['statistics'][1], i['statistics'][2], int(time.time()),
ac['toutiaoid'])

sql = '{}{}{}'.format(sql, fi, sql_i)
if fi == '':
fi = ','

print(sql)
logging.info(sql)
try:
mysql_write(sql)
time.sleep(60)
break
except Exception as e:
logs = '{}--{}'.format('mysql_write', e)
print(logs)
logging.exception(logs)
except Exception as e:
logs = '{}--{}'.format('htmle', e)
print(logs)
logging.exception(logs)



posted @ 2018-01-16 18:35  papering  阅读(175)  评论(0编辑  收藏  举报