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

from selenium import webdriver
from time import sleep
#chromedriver.exe,需要额外下载
bro = webdriver.Chrome(executable_path=r'G:\软件全家桶\Pycharm\Pys15\day137爬虫\chromedriver.exe')
bro.get('https://www.baidu.com/')
text_input = bro.find_element_by_id('kw')
text_input.send_keys('sooele')
sleep(2)
bro.find_element_by_id('su').click()
sleep(2)
#获取当前的页面源码数据
print(bro.page_source)
bro.quit()
#后去豆瓣中更多电影详情数据
from selenium import webdriver
from time import sleep
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')
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)
sleep(1)
bro.quit()

说点什么

avatar
  Subscribe  
提醒