【发布时间】:2020-04-03 12:41:58
【问题描述】:
我正在尝试抓取此页面 - https://www.g2.com/products/dropbox/reviews 但是我一收到请求就会被检测到,有没有办法解决这个问题?
在此之前尝试使用请求,并且也被检测到。 *我不能在这个项目中使用 Scrapy。 而且我在网上找不到有关如何解决它的正确信息...
也许我需要添加自定义标题?
现在代码的输出是(告诉你被检测到的页面标题):
Pardon Our Interruption
代码:
from selenium import webdriver
import selenium as se
def fetch(URL):
options = se.webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument('--incognito')
options.add_argument('--disable-plugins-discovery')
options.add_argument('--start-maximized')
driver = webdriver.Chrome('chromedriver',chrome_options=options)
driver.get(URL)
print(driver.title)
fetch('https://www.g2.com/products/dropbox/reviews')
编辑: 能够四处走动,获得单页,但在第二次运行时,被检测到。 代码:
def fetch(URL):
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
browser = webdriver.Firefox(executable_path='geckodriver.exe', firefox_profile=firefox_profile)
browser.get(URL)
print(browser.title)
fetch('https://www.g2.com/products/dropbox/reviews')
【问题讨论】:
-
你可以看here
-
好吧,我现在可以得到一个页面,但在第二次运行时我被检测到了。可能代理轮换会有所帮助。
-
有时将用户代理字符串编辑为更“正常”的东西。 Selenium 用户代理有点奇怪。虽然很明显这个网站试图阻止你试图执行的确切活动哈哈哈
标签: python selenium google-chrome selenium-webdriver selenium-chromedriver