新人求助 自制的爬虫无法爬取目标网站的点赞数
python3.8 bs4 用的是atom win10系统 自制的爬虫无法爬取目标网站的点赞数from urllib import request,parse,error
import re
from bs4 import BeautifulSoup
page='2.html'
url='http://xiaohua.'+str(page)
headers={
'User-Agent':'Mozilla/4.0(compatible;MSIE 5.5;Windows NT)',
'host':'xiaohua.'
}
try:
req=request.Request(url=url,headers=headers,method='POST')
response=request.urlopen(req)
html=response.read().decode('gbk')
bs=BeautifulSoup(html,'html.parser')
for tag in bs.find_all('em',class_='good-btn'):
article=tag.find('span',class_='text')
print(article)
except error.URLError as e:
if hasattr(e,'code'):
print(e.code)
if hasattr(e,'reason'):
print(e.reason)