鱼C论坛

 找回密码
 立即注册
查看: 1194|回复: 2

[已解决]爬虫中产生了requests.exceptions.ConnectionError

[复制链接]
发表于 2021-8-11 09:58:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
报错如下:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.netbian.comhttps', port=80): Max retries exceeded with url: //pic.netbian.com/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000023052EC3220>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))


第一个get返回的信息没有警告,就从第二个get出现的警告,加上verify=False依然没有解决


代码如下:
import requests
from bs4 import BeautifulSoup
import lxml
if __name__ == '__main__':
    url0 = 'http://www.netbian.com/dongman/'
    res0 = requests.get(url0)
    res0.encoding = 'gbk'
    text0 = res0.text
    soup0 = BeautifulSoup(text0,'lxml')
    soup01 = soup0.find('div',class_='list')
    img_url_list1 = soup01.find_all('li')
    for each0 in img_url_list1:
        middle_url = 'http://www.netbian.com'+\
                     each0.find('a').get('href')
        end_res = requests.get(middle_url,verify=False)
        end_res.encoding='gbk'
        end_soup = BeautifulSoup(end_res.text,'lxml')
        print(end_soup.find('div',class_='pic'))
        name_url = end_soup.find('div',class_='pic').find('img')
        print(name_url)
        img_name = name_url.get('alt')
        img_url = name_url.get('src')
        print(img_name,img_url)
        content = requests.get(img_url).content
        with open('彼岸桌面壁纸下载/'+img_name+'.jpg','wb')as f:
            f.write(content)
            print('好了一个!')
最佳答案
2021-8-11 10:25:10
研究一下html,第三个图片的url不正确
2021-8-11 10-24-49.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-8-11 10:25:10 | 显示全部楼层    本楼为最佳答案   
研究一下html,第三个图片的url不正确
2021-8-11 10-24-49.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-11 15:24:47 | 显示全部楼层
确实如此!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-19 09:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表