爬取网页出现的问题

这是我爬取网页图片产生的问题:

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()

有没有大神帮我看看错哪了。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值