python爬虫常见问题(一)

Python爬虫所见问题集合:

1. NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type

Answer:nth-child 改为 nth-of-type

3.expected string or bytes-like object:

Answer:进行编码转换。

eg:re.findall(r’’,html.decode(‘utf-8’))

4. 'gbk' codec can't encode character '\xa5' in position 184823: illegal multibyte sequence

Answer:f = open(html,’w’,encoding = ‘utf-8’)

5. 网页乱码问题:中文乱码

Answer :response = requests.get(url,headers = header).content

#content解决乱码

扫描二维码关注公众号,回复: 1449097 查看本文章

6. expected string or bytes-like object

Answer:转换为字符串格式,strurls

urls = soup.select(' div > div.nei_left.fl > ul > li:nth-of-type(2)> a')[0]

Href = re.findall(r'<a href="(.*?)" target="" title=".*?">(.*?)</a>',str(urls))

7.  Raise URLError (err)  <urlopen error [Errno 11001] getaddrinfo failed>

通常URLError在没有网络连接(没有路由到特定服务器),或者服务器不存在的情况下产生


猜你喜欢

转载自blog.csdn.net/qq_38354978/article/details/80301910