search

Home  >  Q&A  >  body text

网页爬虫 - python处理中文

最近在学习python爬虫,用的scrapy,基本流程都通顺了,但是发现解析页面中文的时候比较头大。

比如抽取到的内容可能含有 《 【 等字符,这个时候怎么处理?

另外,xpath搜索的时候也有可能需要通过中文匹配,怎么破?

PHPzPHPz2889 days ago434

reply all(4)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:47:17

    You can consider using regular matching.
    Refer to this article: http://blog.csdn.net/gatieme/article/details/43235791

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:47:17

    Use utf8 for everything

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:47:17

    Python3 is much better than python2 in this regard. If you can recommend using python3

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:47:17

    Add encode("utf-8") to the crawled string

    reply
    0
  • Cancelreply