python - 在 linux 中使用 selenium headless 拒绝访问
问题描述
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains
options = Options()
ua = UserAgent()
userAgent = ua.random
print(userAgent)
# below trick saved my life
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument(f'user-agent={userAgent}')
# Optional argument, if not specified will search path.
driver = webdriver.Chrome('chromedriver',options=options)
wait = WebDriverWait(driver, 20)
action = ActionChains(driver)
driver.execute_script("return navigator.userAgent")
# Scraping steps
url = "https://www.costco.com"
driver.get(url)
driver.delete_all_cookies()
time.sleep(3)
print(driver.title)
driver.quit()
试图访问这个 url 并且访问被拒绝
我认为这个网站阻止了我的 ip
操作系统:AWS Linux
Python:3.7
我已经尝试了以下方法
- 用户代理
- 等待
- 动作链
- delete_all_cookies()
请问有什么方法可以帮助我吗?
解决方案
推荐阅读
- python - 如何创建机器学习模型列表?
- r - 使用 UTF-8 编码将 csv 文件导入 R 数据帧
- vba - Word 用户 VBA 设置为文本框边框样式
- destructuring - 这个对象是解构的还是其他的?
- instrumentation - 使用 maven-surefire 从 javaagent 访问测试类
- javascript - 检测表默认值的变化(Django)
- c# - Akka.net 在 /user 下的 Actor 名称中添加一个随机数
- salesforce - 有没有办法将 Microsoft Bot Framework 移交集成到 Salesforce Live 代理
- reactjs - 强类型对象属性依赖于其他对象属性
- python - 在 python BeautifulSoup 或 selenium 中从任何网站中提取社交链接