为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过 Selenium 和 Python 从谷歌搜索结果中单击随机链接

如何通过 Selenium 和 Python 从谷歌搜索结果中单击随机链接

MM们 2021-05-30 21:50:42
当前使用Selenium + Python和以下代码:browser.get('http://www.google.com')search = browser.find_element_by_name('q')search.send_keys("how to search the internet")search.send_keys(Keys.RETURN) # hit return after you enter search texttime.sleep(5) # sleep for 5 seconds so you can see the resultsbrowser.execute_script("window.scrollTo(0, 873)") time.sleep(2)browser.find_element(By.XPATH, '(//h3)[3]/a').click()`作为我的代码。发生什么:转到Google并输入单词并点击搜索。向下滚动一点,然后点击第一个链接我想要的是:我希望能够从搜索结果页面中单击随机链接这该怎么做?编辑:这就是我说不必要时的意思:不必要的 1:https ://imgur.com/a/70qz89x不必要的2:https : //imgur.com/a/8WWvcnC这些是我想要的唯一结果:这个:https : //imgur.com/a/eTatFV9
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 200 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号