如何使用Python在Selenium Webdriver Chrome中启用JavaScript

如何使用Python在Selenium Webdriver Chrome中启用JavaScript

问题描述:

我正在尝试使用Selenium Webdriver打开 https://www.guidestar.org/,但是能够检测到我是机器人.我收到的电子邮件说未启用javascript,因此它们阻止了我的IP地址.谁能建议一个代码来启用javascripts

I am trying to open https://www.guidestar.org/ using selenium webdriver but it is able to detect I am a bot. The email I received says that javascript was not enabled so they were blocking my IP address. Can anyone suggest a code to enable javascripts

user_agent = 'Chrome/73.0.3683.86'
username = os.getenv("USERNAME")
userProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
options = webdriver.ChromeOptions()
options.add_argument(f'user-agent={user_agent}')
options.add_argument("user-data-dir={}".format(userProfile))
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://www.guidestar.org")

我希望网站不要检测到我是机器人

I expected the website not to detect that I am a robot

此处提供的答案无效. 而是使用

answers provided here won't work. instead, use

    options.add_argument("--enable-javascript")