1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding:utf-8 -*-
# @Time : 2020/5/28 16:21
# @Author : litao
# -*- coding:utf-8 -*-
# @Time : 2020/5/28 15:19
# @Author : litao
from selenium import webdriver
import redis, datetime,time,json
from crawler.crawler_sys.utils.trans_str_play_count_to_int import trans_play_count
rds = redis.StrictRedis(host='192.168.17.60', port=6379, db=15, decode_responses=True)
class CrawlerMain(object):
def __init__(self):
self.chrome_options = webdriver.ChromeOptions()
# self.chrome_options.add_argument('--disable-gpu')
self.chrome_options.add_argument("--start-maximized")
self.chrome_options.add_argument("--no-sandbox")
self.chrome_options.add_argument('disable-infobars')
# 请根据chrome版本 下载chrome driver http://npm.taobao.org/mirrors/chromedriver/
self.driver = webdriver.Chrome(options=self.chrome_options)
def login(self):
self.driver.get("https://m.yangshipin.cn/video?type=2&vid=2004011401&pid=600036243&ptag=4_1.4.2.20898_wxf")
while True:
now = datetime.datetime.now()
res = self.driver.find_elements_by_xpath("//span[@class='p-video-intro-person']")
if res:
play_count = trans_play_count(res[0].text)
print(play_count)
dic = {
"menber":play_count,
"fetch_time":int(now.timestamp()*1e3)
}
rds.rpush("toutiao", json.dumps(dic))
time.sleep(200)
def __exit__(self):
self.driver.close()
if __name__ == "__main__":
test = CrawlerMain()
test.login()