爬虫遇到的问题及解决方法

Python3 unicode转中文

今天使用 python3.7 版本写爬虫的时候输出信息应该是中文,但是实际是显示为中文的 unicode 的形式,后去查资料后,有方法说使用 decode 方法,但是我使用 decode 方法却提示我 AttributeError: 'str' object has no attribute 'decode' 错误,继续查找资料发现 Python3 以上取消了 decode 方法,所以直接对字符串进行 decode 操作就会报错。正确操作方式如下:

1
str.encode('utf-8').decode('unicode-escape')

Scrapy 提示 DEBUG: Filtered offsite request to ‘xxx.com’

出现此问题需要修改 spider.py 文件中 allowed_domains 项:将allowed_domains = [‘www.zhenai.com']更改为allowed_domains = [‘zhenai.com’] 即更换为对应的一级域名。


-------------本文结束感谢您的阅读-------------

本文标题:爬虫遇到的问题及解决方法

文章作者:Tang

发布时间:2019年02月10日 - 19:02

最后更新:2019年02月12日 - 11:02

原始链接:https://tangx1.com/solved/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%