from selenium import webdriver
from selenium.webdriver.common.keys import Keys
broesor =webdriver.Chrome()
# 创建一个chrome调试浏览器
broesor.get('http://www.baidu.com/index.html')
broesor.find_element_by_name('kw1')
# 根据name来寻找
broesor.find_element_by_id('wd1')
# 根据id来进行寻找
broesor.find_element(by='id',value='wd1')
# 根据id来进行寻找
broesor.find_element_by_class_name('td_header')
# 根据class的值来寻找
broesor.find_element_by_xpath('//*[id="td"]/span[1]/a')
# 根据xpath来寻找
broesor.find_element_by_xpath('//*[id="td"]/span[1]/a').click()
# 点击该路径的按钮
kw=broesor.find_element_by_id('wd')
kw.send_keys('李毅',Keys.ENTER)
# 寻找到id的所在,输入内容,并且回车
while True:
for i in range(10):
broesor.execute_script('window.scrollBy(0,1000)')
# 循环滚动
broesor.execute_script('window.scrollTo(0,document.body.scrollHeight)')
# 滚动到最后
print(broesor.page_source)
# 打印网页的html代码
broesor.close()
# 关闭
python爬虫的selenium库的使用
最新推荐文章于 2025-02-28 20:40:03 发布
此博客围绕Python爬虫中Selenium库的使用展开,虽未给出具体内容,但可知聚焦于利用该库进行网页数据抓取等爬虫相关操作,Selenium库能助力模拟浏览器行为,在爬虫领域有重要应用。
880

被折叠的 条评论
为什么被折叠?



