拒绝访问 您无权访问“站点";通过 Selenium Python 在此服务器上使用 ChromeDriver 和 Chrome

问题描述

我一直在使用 selenium 和 chrome,我一直在尝试访问一个网站,但我一直收到以下错误消息:

I've been using selenium with chrome and I've been trying to access a website but I keep receiving this error message:

Access Denied You don't have permission to access "website" on this server.

该网站在我的常规 chrome 浏览器上运行良好,但通过 selenium 打开时我收到此错误消息.

The website works fine on my regular chrome browser, but when opened through selenium I receive this error message.

我已尝试对错误进行常规故障排除,但没有帮助,我已尝试安装 firefox 但导致另一个错误:消息:无法找到匹配的功能集"

I've tried the regular troubleshooting for the error but it didn't help, I've tried installing firefox but that resulted in another error: "Message: Unable to find a matching set of capabilities"

browser = webdriver.Chrome('C:\UsersFerdinandDownloadschromedriver_win32chromedriver.exe')
browser.get('https://www.vitacost.com/MyAccount/Login.aspx')

我完全卡在这里了,我在另一台电脑上试了一下,结果还是一样.

I'm completely stuck here, I tried it another computer and still the same result.


解决方案

如果你的尝试有 Headless 选项,我认为它可能与用户代理有关.因为有些网站用 Headless 屏蔽了用户代理.

If your trying has Headless option, I think it might be related to user-agent. Because some web site block the user-agent with Headless.

所以,去 https://www.whatsmyua.info/ 找到您的用户代理可以在您的常规 chrome 浏览器中使用,然后再试一次.

So, go to https://www.whatsmyua.info/ to find your user-agent which works in your regular chrome browser and try again with this.

ChromeOptions options = new ChromeOptions();
String userAget = "YOUR USER AGENT";
options.addArguments(String.format("user-agent=%s", userAgent));

这是一个 java 代码,但我相信在 python 中有完全相同的方式.

This is a java code but I believe there is an exactly same way in python.

相关文章