V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-01-02 19:32:33 +08:00 · 1895 次点击
    这是一个创建于 1912 天前的主题,其中的信息可能已经有所发展或是发生改变。

    网址: 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 条回复    2019-01-02 22:31:20 +08:00
    chengxiao
        1
    chengxiao  
       2019-01-02 22:26:04 +08:00
    luoleng
        2
    luoleng  
       2019-01-02 22:31:20 +08:00
    from parsel import Selector
    Selector(text).xpath('your_xpath').extract()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3925 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:11 · PVG 13:11 · LAX 22:11 · JFK 01:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.