Python爬取
1.爬取内容:对某网站内容与热度进行爬取
分析:我们所需的数据是热搜榜的1—10,第一个数据pass
divs = html.xpath('//div[@class="wbpro-side-card7"]/div[position()>1]')
2.解决没有热力的问题:
别的内容都有热力,但是内容有的热搜内容没有热力,我们取值是会有问题。
解决方法:
if len(hot) == 0:
hot = 0
else:
hot = hot[0]
3.先解决代码报错:
1.UnicodeDecodeError:'utf-8’e0dec can’t decode byte 0xca in position 339: invalid continuation byte
content = response.content.decode