admin管理员组文章数量:1579084
1、cmd安装selenium,输入pip install selenium
2、模拟点击热搜第一条进去,连接如下
https://weibo/newlogin?tabtype=weibo&gid=102803&openLoginLayer=0&url=https%3A%2F%2Fweibo%2F
3、查看谷歌版本
4、并去下面下载对应版本的webdriver,解压后把chromedriver.exe放入python目录
CNPM Binaries Mirrorhttps://registry.npmmirror/binary.html?path=chromedriver/
3、写代码测试
from selenium import webdriver
from selenium.webdrivermon.by import By
import time
option = webdriver.ChromeOptions()
#此配置去掉浏览器正在受自动软件的监控
option.add_experimental_option('excludeSwitches', ['enable-automation'])
#模拟浏览器点击
option.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"')
#设置信息
driver = webdriver.Chrome(options=option)
#浏览器最大化,不放大有可能页面会兼容手机隐藏掉,之前小窗口老是xpath获取不到数据
driver.maximize_window()
# 打开chrome浏览器
driver.get("https://weibo/newlogin?tabtype=weibo&gid=102803&openLoginLayer=0&url=https%3A%2F%2Fweibo%2F/")
#网页打开要等待全部加载完才能获取到节点
time.sleep(15)
#获取微博热搜第一个点进去
hots = driver.find_elements(By.XPATH,"//div[@class='wbpro-side-card7']/div[@class='wbpro-side-panel']/a");
for hot in hots:
hot.click()
break;
print(driver.current_url)
time.sleep(5)
driver.quit()
4、完事了~~~后面持续更新
版权声明:本文标题:python用selenium模拟谷歌浏览器点页面 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727850321a1133504.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论