【发布时间】:2021-05-12 15:55:31
【问题描述】:
我从谷歌搜索结果中复制了大约 100000 个链接。我使用 selenium 编写了一个 python 代码来让我的生活更轻松,但是一旦我到达大约 150 个结果,谷歌搜索结果页面就会发生变化,因为我认为谷歌正在检测我的抓取工具。这是我的代码示例:
links = []
# Extracting the 10 links in the google page
soup = BeautifulSoup(driver.page_source, 'html.parser')
sleep(randTime(0,1))
search = soup.find_all('div', class_="yuRUbf")
for h in search:
links.append(h.a.get('href'))
sleep(randTime(0,1))
#Clicking the next button
next_button = driver.find_element_by_xpath("//a[@id='pnnext']")
sleep(randTime(0,5))
next_button.click()
sleep(randTime(2,10))
非常感谢您的帮助,我在代码执行期间使用了随机睡眠,但它们不起作用。您有什么可以提供帮助的建议吗?
这是我得到的错误:
NoSuchElementException: Message: no such element: Unable to locate element:
{"method":"xpath","selector":"//a[@id='pnnext']"}
(Session info: headless chrome=90.0.4430.93)
【问题讨论】:
-
是什么让您认为自己被准确检测到了?嗯......我不能肯定地说,但我相信绕过反自动化安全的东西违反了 stackoverflow TOS。
-
我得到元素未找到下一个按钮的异常
标签: python selenium web search automation