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

scrapy 请求返回的乱码,如何解决

  •  
  •   Ewig · Jan 2, 2019 · 2347 views
    This topic created in 2672 days ago, the information mentioned may be changed or developed.

    网址: http://www.hkexnews.hk/APP/SEHKAppMainIndex_c.htm linkList =response.xpath(u'//td[@class="pming_black12 ms-rteTableOddCol-BlueTable_CHI"]/a/@href').extract()

    scrapy 中我这样写匹配是空,原因返回的编码是乱码 但是我这样写 response.body.decode(encoding="utf-8").xpath( '//td[@class="pming_black12 ms-rteTableOddCol-BlueTable_CHI"]/a/text()')

    说字符串没有 xpath ,这个如何解决?求人指教?

    xpath 没有问题,因为我用 request 测试过

    注:不能用正则 只能用 scrapy 内置的方法,谢谢

    2 replies    2019-01-02 22:31:20 +08:00
    chengxiao
        1
    chengxiao  
       Jan 2, 2019
    luoleng
        2
    luoleng  
       Jan 2, 2019
    from parsel import Selector
    Selector(text).xpath('your_xpath').extract()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3661 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    ♥ Do have faith in what you're doing.