“ResultSet”对象没有属性“find_all”,unable to get local issuer certificate (_ssl.c:1108)问题解决

from bs4 import BeautifulSoup
import urllib.request

url='https://topic.autohome.com.cn/new/home/sos.jsp?isNonCar=0&nonCar=0&brandId=25&seriesId=0&page=1'
open_it = urllib.request.urlopen(url)  

报错:urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108),是浏览器的认证问题。

解决方式是使用requests第三方库,这个库可不是Python3内置的urllib.request库,而是一个强大的基于urllib3的第三方库。

pip install requests

然后再来,targets_url = bf.find_all(class_=‘result-list’)会报错,改成targets_url = bf.find(class_=‘result-list’)就可以了。

from bs4 import BeautifulSoup
import requests
                                                        
url='https://topic.autohome.com.cn/new/home/list.jsp?typeId=3' 
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'} 
req = requests.get(url = url,headers = headers)  
                       
req.encoding = 'utf-8'                                                  
html = req.text                                                         
bf = BeautifulSoup(html, 'html.parser') 
targets_url = bf.find(class_='result-list')                
url_set = set() 

for each in targets_url.find_all('a'):  
	if 'class' not in each.attrs.keys():  
		url_set.add(each['href']) 
print(url_set)
{'http://topic.autohome.com.cn/new/marketing/2019/12/jetour/',
 'https://topic.autohome.com.cn/act/marketing/2019/12/escape/',
 'https://topic.autohome.com.cn/act/marketing/2019/12/mustang/',
 'https://topic.autohome.com.cn/new/marketing/2019/11/kx3/',
 'https://topic.autohome.com.cn/new/marketing/2019/11/tengshi/',
 'https://topic.autohome.com.cn/new/marketing/2019/11/wmex5/',
 'https://topic.autohome.com.cn/new/marketing/2019/12/compass/',
 'https://topic.autohome.com.cn/new/marketing/2019/12/jkdzddg/',
 'https://topic.autohome.com.cn/new/marketing/2020/1/corsair/',
 'https://topic.autohome.com.cn/new/marketing/2020/3/xingyue/',
 'https://topic.autohome.com.cn/new/marketing/2020/4/t77pro/',
 'https://topic.autohome.com.cn/new/marketing/2020/4/xiaopeng/'}

关注微信公众号:“数据分析师手记”
在这里插入图片描述

数据分析之家联合JEE RAY品牌为粉丝派发福利

在这里插入图片描述
添加粉丝福利派发官,领取粉丝福利哦

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值