我们实验室与一家网络公司合作,开发了可以保护网页不被网络爬虫抓取的技术。测试网站是http://119.254.209.77/ .我无法获取左侧页面(例如“正在检查”)的网址。当我点击链接时,它会创建一个url。使用Python+Selenium+Firefox,我模拟了点击操作,但我得到了一个空白页面而不是真实的数据。如果我自己点击链接,它会返回真实的数据。所以我想知道当我在firefox中使用selenium webdriver时,服务器如何识别我是网络爬虫?我还想知道如何避免被其网站视为网络爬虫。
这是我的代码:
driver = webdriver.Firefox() driver.get('http://119.254.209.77/') time.sleep(5) pageSource = driver.page_source print(driver.page_source) # the target url checking = driver.find_element_by_id('_ctl0__ctl0_Content_MenuHyperLink2') # it seems to has no effects checking.click() time.sleep(2) print(driver.page_source)
最佳答案
在将您转到下一页之前,该网站似乎正在检查您的鼠标所在位置。在单击元素之前移动到它对我有用:
driver = webdriver.Chrome()
driver.get('http://119.254.209.77/')
time.sleep(5)
pageSource = driver.page_source
print(driver.page_source)
# the target url
checking = driver.find_element_by_id('_ctl0__ctl0_Content_MenuHyperLink2')
action_chain = webdriver.ActionChains(driver)
action_chain.move_to_element(checking)
action_chain.click(checking)
action_chain.perform()
time.sleep(2)
print(driver.page_source)
关于python - 使用selenium webdriver爬取网页时,服务器如何区分是机器人还是人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38320811/