这是我爬取网页图片产生的问题:
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.netbian.com', port=443): Max retries exceeded with url: /index.htm (Caused by SSLError(SSLError(1, '[SSL: LENGTH_MISMATCH] length mismatch (_ssl.c:1129)')))
以下是我的代码:
```python
import requests
import re
import time
head = {"User-Agent":
r"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3870.400 QQBrowser/10.8.4405.400"}
def picture_download(url_img_path, img_title):
file_name = img_title.replace('/', '')
result = requests.get(url_img_path)
print(url_img_path, 'Download failed')
if result.status_code == 200:
path = r'D:\本机照片\%s.jpg' % file_name
with open(path, 'wb') as File:
File.write(result.content)
def Img_Url(url):
result = requests.get(url=url,headers=head)
result.encoding = 'gbk'
compile = re.compile(r'<img src=(.*?) alt=(.*?)>')
all = compile.findall(result.text)
for item in all:
print(item[0], item[1])
picture_download(url_img_path=item[0], img_title=item[1])
def main():
for i in range(1, 2):
if i == 1:
Img_Url(r'http://www.netbian.com/index.htm')
else:
Img_Url('http://www.netbian.com/index_%d.htm' % i)
time.sleep(2)
if __name__ == "__main__":
main()
有没有大神帮我看看错哪了。。。