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
yangjiaronga
V2EX  ›  Python

Scrapy xpath 匹配不到一些数据

  •  
  •   yangjiaronga · Feb 6, 2017 · 2654 views
    This topic created in 3372 days ago, the information mentioned may be changed or developed.
    <table class="tabledataformat" cellspacing="0" >
    	<tr>
    		<td style="vertical-align:top;">Copper, Cu&nbsp;</td>
        	<td class="dataCell" style="vertical-align:top;"><= 0.03 %<span 		     class="dataCondition"></span></td>
        	<td class="dataCell" style="vertical-align:top;"><= 0.03 %<span class="dataCondition"></span></td>
        	<td class="dataComment" style="vertical-align:top;"></td>
        </tr>
    </table>
    

    response.xpath('//table[@class="tabledataformat"]/tr').extract() 只能获取到

    <tr>
    		<td style="vertical-align:top;">Copper, Cu&nbsp;</td>
        	<td class="dataCell" style="vertical-align:top;"></td>
        	<td class="dataCell" style="vertical-align:top;"></td>
        	<td class="dataComment" style="vertical-align:top;"></td>
        </tr>
    

    <= 0.03 % 和 消失不见,为什么呢?

    4 replies    2017-03-07 10:56:49 +08:00
    imn1
        1
    imn1  
       Mar 4, 2017
    因为<=的写法不符合 xml 标准
    leavic
        2
    leavic  
       Mar 4, 2017
    这部分数据可能是 javascript 异步请求显示的,也就是 ajax 内容, scrapy 是看不到的。
    dsg001
        3
    dsg001  
       Mar 4, 2017
    '''
    <tr> <td style="vertical-align:top;">Copper, Cu&#160;</td> <td class="dataCell" style="vertical-align:top;">&lt;= 0.03 %<span class="dataCondition"></span></td> <td class="dataCell" style="vertical-align:top;">&lt;= 0.03 %<span class="dataCondition"></span></td> <td class="dataComment" style="vertical-align:top;"></td> </tr>
    '''

    测试 lxml 能输出, scrapy 应该也没问题,查看 html 源码吧
    crazypig14
        4
    crazypig14  
       Mar 7, 2017
    scrapy 爬下来用 beautifulsoup 处理,我觉得方便些
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2501 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 02:43 · PVG 10:43 · LAX 19:43 · JFK 22:43
    ♥ Do have faith in what you're doing.