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解决乱码
6. expected string or bytes-like object
Answer:转换为字符串格式,str(urls)
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在没有网络连接(没有路由到特定服务器),或者服务器不存在的情况下产生