Python爬虫selenium无页面(Chrome页面数据动态加载)

#后去豆瓣中更多电影详情数据
from selenium import webdriver
from time import sleep
#谷歌无头(页面)浏览器
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
url = 'https://movie.douban.com/typerank?type_name=%E6%83%8A%E6%82%9A&type=19&interval_id=100:90&action='
bro = webdriver.Chrome(executable_path=r'G:\软件全家桶\Pycharm\Pys15\day137爬虫\chromedriver.exe',chrome_options=chrome_options)
bro.get(url)
sleep(3)
bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(3)
bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(3)
bro.execute_script('window.scrollTo(0,document.body.scrollHeight)')
sleep(3)
page_text = bro.page_source
#print(page_text)

with open('./Web/douban.html','w',encoding='utf-8')as fp:
    fp.write(page_text)
print(page_text)
sleep(1)
bro.quit()

 

说点什么

avatar
  Subscribe  
提醒