求教大神用python爬虫爬网站时报ValueError: invalid literal for int() with base 10
代码如下:
#导入模块
import urllib.request
import os
#打开网址
def url_open(url):
# headers = {‘User-Agent’,‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3534.4 Safari/537.36’}
req = urllib.request.Request(url)
req.add_header(‘User-Agent’,‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3534.4 Safari/537.36’)
response = urllib.request.urlopen(req)
html = response.read()
return html
#获取页数
def get_page(url):
html = url_open(url).decode(‘utf-8’,‘ignore’)
a = html.find('current-comment-page') + 30
b = html.find(']',a)
return html[a:b]
#找到图片
def find_img(url):
html = url_open(url).decode(‘utf-8’,‘ignore’)
img_addrs = []
a