Selenium 配合 Chromedriver 爬取艺龙评价时,存在内嵌窗口,直接 JS 无法滚动,这里使用如下操作方法
if spider.name == 'elong':
for i in range(2):
rand = random.uniform(1, 4)
time.sleep(rand)
drag = self.driver.find_element_by_xpath("//li[@class='s_bdt'][last()-1]")
self.driver.execute_script("arguments[0].scrollIntoView();", drag)
time.sleep(2)
else:
for i in range(2):
rand = random.uniform(1, 4)
time.sleep(rand)
js = "window.scrollTo(0,document.body.scrollHeight)"
self.driver.execute_script(js)
print('Chrome driver success...')