【发布时间】:2018-10-30 08:11:42
【问题描述】:
soup = BeautifulSoup(browser.page_source, "html.parser")
for h1 in soup.find_all('h2'):
try:
array.append("https://www.chamberofcommerce.com" + h1.find("a")['href'])
print("https://www.chamberofcommerce.com" + h1.find("a")['href'])
except:
pass
input=browser.find_element_by_xpath('//a[@class="next"]')
while input:
input.click()
time.sleep(10)
soup = BeautifulSoup(browser.page_source, "html.parser")
for h1 in soup.find_all('h2'):
try:
array.append("https://www.chamberofcommerce.com" + h1.find("a")['href'])
print("https://www.chamberofcommerce.com" + h1.find("a")['href'])
except:
pass
这部分代码删除了yellopages上列表的url,代码运行良好,直到我过去只从搜索的第一页删除url,现在我希望它点击下一步按钮,直到搜索页面完成, Foe Example 如果有 20 页的搜索,那么 selenuim 机器人应该点击下一步按钮并删除 url,直到它到达第 20 页,
请查看代码的逻辑,并且在机器人到达第 2 页后我收到以下错误,实际页数为 15,它在第 2 页崩溃:
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
【问题讨论】:
标签: python-3.x selenium beautifulsoup