推荐学习书目
› 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
JianBingXia
V2EX  ›  Python

webdriver.PhantomJS 有个疑问求玩蛇高手

  •  
  •   JianBingXia · Aug 3, 2016 · 3317 views
    This topic created in 3714 days ago, the information mentioned may be changed or developed.

    最近想获取一个 js 生成的网页 拿百度举个例子 搜刘德华的图片

    http://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&word=%E5%88%98%E5%BE%B7%E5%8D%8E#z=0&pn=&ic=0&st=-1&face=0&s=0&lm=-1

    这是一个 js 生成的网页

    如果我用

    driver = webdriver.PhantomJS()

    driver.get(url)

    driver.page_source

    获取到的还是 js 之前的 html,请问我该如何获取之后生成的整页 html 呢?

    谢谢

    ps.使用driver.find_elements_by_xpath('//a[@name="pn0"]/img')和get_attribute("src") 是可以获取到内容的,如果我想获取整个img的html标签应该怎么取呢?

    1 replies  •  2016-08-03 18:34:39 +08:00
    Magic347
        1
    Magic347  
       Aug 3, 2016
    页面应该是有 1 个 ajax 请求的:
    http://image.baidu.com/search/avatarjson?tn=resultjsonavatarnew&ie=utf-8&word=%E5%88%98%E5%BE%B7%E5%8D%8E&cg=star&pn=60&rn=30&itg=0&z=0&fr=&lm=-1&ic=0&s=0&st=-1&gsm=d0000003c

    word 参数作为输入关键词,注意 urlencode 一下
    pn 参数来控制页长偏移量
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   792 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:02 · PVG 06:02 · LAX 15:02 · JFK 18:02
    ♥ Do have faith in what you're doing.