推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
kukuwhu
V2EX  ›  Python

用 selenium 时,除了 phantomjs 还有哪些浏览器支持 headless mode(无桌面环境的命令行)运行?

  •  
  •   kukuwhu · Oct 18, 2016 · 4299 views
    This topic created in 3631 days ago, the information mentioned may be changed or developed.

    在做爬虫的时候,经常碰到 requests 搞不定的时候上 webdriver ,但基于 selenium 的 chrome 必须在桌面环境运行(会弹出浏览器窗口),而用支持命令行启动的 phanjstom 请求的时候很多网页都有反爬(不知道怎么识别的),有没有其他的浏览器支持 Linux 的无窗口环境运行? firefox 之类的支持吗?谢谢

    11 replies  •  2016-10-18 17:56:07 +08:00
    jetyang
        1
    jetyang  
       Oct 18, 2016   ❤️ 1
    firefox 、 chrome 都可以啊,配合 Xvfb 使用。如果用 chrome 要单独安装 chromedriver , firefox 不用额外装东西,网上教程有一些,挺容易配置的
    cheetah
        2
    cheetah  
       Oct 18, 2016
    ls 说的对,可以搜下 webdriver
    至于 phanjstom 怎么被识别的,只能是 ua 了吧
    Python 的话还可以用 ghost.py
    kukuwhu
        3
    kukuwhu  
    OP
       Oct 18, 2016
    @jetyang 好的,非常感谢,另外再请教下,理论上用 phantomjs 通过配置 desired_capabilities 可完全模拟 chrome,但为什么我用 chrome 可打开页面,用 phantomjs 返回的是明显做了反爬的空 html 页面?除了配置 desired_capabilities 的 useragent 为 chrome 还有其他地方有差异吗?
    kukuwhu
        4
    kukuwhu  
    OP
       Oct 18, 2016
    @cheetah 我是用的 chromedriver ,必须要在视窗界面下运行才不报错,应该是 jetyang 说的,需要配置一下 xvfb
    cheetah
        5
    cheetah  
       Oct 18, 2016
    @kukuwhu 是的
    jetyang
        6
    jetyang  
       Oct 18, 2016
    @kukuwhu 我没用过 phantomjs ,一直用的 webdriver 。别人防抓取的策略可能比较高级吧,比如限制单 IP 访问频次、 cookie 保持等等,爬不到正确内容要分析具体原因
    L2AKnG8GXx60bc6P
        7
    L2AKnG8GXx60bc6P  
       Oct 18, 2016
    @jetyang 请教一下,下载了 chromedriver 之后还用安装 chrome 吗?如果用怎么在命令行下安装 chrome 呢?
    jetyang
        8
    jetyang  
       Oct 18, 2016
    @relic 我都装了,环境是 centos ,必须 centos 7 以上才能装 chrome , yum install chrome , chromedriver 我记得是个可执行文件,下载解压就可以用了。好像还有一个坑: chrome 不能以 root 用户启动,记不清了,你试试看
    gimp
        9
    gimp  
       Oct 18, 2016
    安装 chrome 可以用这个全自动脚本,要求 Centos6 以上版本

    https://chrome.richardlloyd.org.uk/
    gimp
        10
    gimp  
       Oct 18, 2016
    之前折腾的时候整理点 Xvfb 和 selenium

    https://blog.ishell.me/a/selenium-with-xvfb.html
    gimp
        11
    gimp  
       Oct 18, 2016
    手抖... 还有个 https://blog.ishell.me/a/xvfb-screenshot-capture.html 稍微填了下上边的坑
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2834 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 14:04 · PVG 22:04 · LAX 07:04 · JFK 10:04
    ♥ Do have faith in what you're doing.