(72)--爬取中执行JS代码

# 用JS代码自动运行程序

from selenium import webdriver
import time
chrome = webdriver.Chrome(executable_path=r'E:\Python\python爬虫\chromedriver.exe')
base_url = 'https://image.baidu.com/search/index?ct=201326592&cl=2&st=-1&lm=-1&nc=1&ie=utf-8&tn=baiduimage&ipn=r&rps=1&pv=&fm=rs8&word=%E6%A8%B1%E8%8A%B1%E7%BE%8E%E5%A5%B3&oriquery=%E6%A8%B1%E8%8A%B1&ofr=%E6%A8%B1%E8%8A%B1&sensitive=0'
chrome.get(base_url)
for i in range(0,29):
    time.sleep(0.5)
    html = chrome.page_source

    chrome.execute_script('scrollTo(0,document.body.scrollHeight)')


# 爬取结果如下:

(72)--爬取中执行JS代码_第1张图片



兄弟连学python


Python学习交流、资源共享群:563626388 QQ



你可能感兴趣的:(Python爬虫)