V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
godluo
V2EX  ›  Python

scrapy 如何爬取网页元素显示样式设置为不可见(即 style="display:none")标签下的内容

  •  
  •   godluo · Oct 28, 2018 · 4537 views
    This topic created in 2741 days ago, the information mentioned may be changed or developed.
    如题,scrapy 新手请教,如何爬取网页元素显示样式设置为不可见(即 style="display:none")标签下的内容:
    网页源码如下:
    <dl class="xxx" style="display:none">
    <li>
    <span class="fl">text1</span>
    <p class="fl">text11</p>
    </li>
    <li>
    <span class="fl">text2</span>
    <p class="fl">text22</p>
    </li>
    </dl>

    请教如何操作?谢谢!
    6 replies    2018-10-29 17:18:08 +08:00
    Trim21
        1
    Trim21  
       Oct 29, 2018 via Android
    元素 display:none 会导致 xpath 选不到吗?
    thedog
        2
    thedog  
       Oct 29, 2018 via Android
    不可见,源码里还是有的,有什么影响吗?
    NLL
        3
    NLL  
       Oct 29, 2018
    一样可以 xpath 取到的
    xpresslink
        4
    xpresslink  
       Oct 29, 2018
    不可见样式是指浏览器渲染方式不让人眼见,然而你爬虫取到的是网页的字符串。
    Qzier
        5
    Qzier  
       Oct 29, 2018 via iPhone
    有什么区别吗?
    godluo
        6
    godluo  
    OP
       Oct 29, 2018 via Android
    scrapy shell ,元素 display:none 会导致 xpath 选不到。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2649 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:17 · PVG 11:17 · LAX 20:17 · JFK 23:17
    ♥ Do have faith in what you're doing.