|
|
发表于 2019-10-25 00:33:17
|
显示全部楼层
本帖最后由 XiaoPaiShen 于 2019-10-25 00:34 编辑
我用你的代码无法decode html
我就使用了自动下载设置代理
首先把 【爬虫福利】自动下载设置代理 中的代码保存下来,取文件名为proxypool.py
- import proxypool as pool
- import urllib.parse
- import re
- ##def get_html(url):
- ## html = urllib.request.urlopen(url).read()
- ## x = chardet.detect(html)['encoding']
- ## html = html.decode(x)
- ## return html
- proxy = pool.ProxyPool()
- url = 'https://fishc.taobao.com'
- html = proxy.read_url(url, decode='text')
- # html = get_html(url)
- img_address = re.findall(r'<img src="([^"]+)"', html)[1]
- # print(img_address)
- img_url = urllib.parse.urljoin('http:', img_address)
- print(img_url)
- # x = get_html('http://' + img_address)
- '''
- for i in img_address:
- x = 1
- urllib.request.urlretrieve('http://' + i, '%d.jpg'%x)
- x += 1
- '''
复制代码 |
|