HeadlessChrome 未被 Barnes and Noble 网站视为真实用户

HeadlessChrome is not regarded as a real user by Barnes and Noble website

我使用 Chrome-Headless 的原因是因为它就像一个真正的浏览器,但是当我将 chrome-headless + Selenium 指向这个 Barnes and Noble link:

https://www.barnesandnoble.com/w/the-woman-they-could-not-silence-kate-moore/1138489968?ean=9781728242576

我得到了这个回复,没有导航到任何其他页面

<html><head>
<title>Access Denied</title>


</head><body>
<h1>Access Denied</h1>
 
You don't have permission to access "https://www.barnesandnoble.com/w/the-woman-they-could-not-silence-kate-moore/1138489968?ean=9781728242576" on this server.<p>
Reference #


</p></body></html>

我知道我需要添加 headers 等等,但这与常规 GET 请求 + Headers 有何不同?

还有什么特别是 Chrome-headless 送给巴恩斯和诺贝尔?

我做错了什么?

我错过了什么?

您看到以下 错误页面:

由于存在关键字 within the

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/98.0.4758.102 Safari/537.36

解决方案

您可以使用其他一些常规 覆盖默认 useragent,如下所示:

  • 代码块:

    options = Options()
    options.headless = True
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument('--disable-blink-features=AutomationControlled')
    options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36")
    s = Service('C:\BrowserDrivers\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    driver.get("https://www.barnesandnoble.com/w/the-woman-they-could-not-silence-kate-moore/1138489968?ean=9781728242576")
    driver.save_screenshot("barnesandnoble.png")
    
  • 截图:


参考资料

您可以在以下位置找到一些相关的详细讨论:

  • How to change the displayed operating system information within the useragent using Selenium and Python?