在无界面模式下发现请求地址全部报404,在有界面的模式下就是正常运行的。在网上查了半天,发现这种情况,由于爬取的网站进行了selenium反爬虫导致的。

1.尝试使用开启开发者模式

opt = webdriver.ChromeOptions()

# 把chrome设置成无界面模式,不论windows还是linux都可以,自动适配对应参数
opt.set_headless()
# 创建chrome无界面对象
opt.add_argument("--start-maximized") # 界面设置最大化
# opt.add_argument('no-sandbox')
opt.add_argument('--headless')
opt.add_argument('--disable-gpu')
opt.add_experimental_option('excludeSwitches', ['enable-automation'])#开启开发者模式
driver = webdriver.Chrome(options=opt)

运行之后还是会报404,这种方法放弃

2.尝试使用firefix浏览器

opt=webdriver.FirefoxOptions()
opt.set_headless()
opt.add_argument("--start-maximized")
opt.add_argument('--headless')
opt.add_argument('--disable-gpu')
driver = webdriver.Firefox(options=opt)

成功解决问题,在无界面模式下可以爬取,

https://github.com/mozilla/geckodriver/releases/ 该链接可以下载新的火狐浏览器驱动



 

相关文章:

  • 2022-02-25
  • 2021-10-12
  • 2021-12-05
  • 2021-09-11
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-08-10
  • 2022-12-23
  • 2022-02-14
  • 2021-11-19
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案