我试图下载所有的网页标题https://ec.europa.eu/eurostat/news/news-releases,但它们都有相同的类,所以当我只使用find进行筛选时,我只会得到第一个。使用FindAll方法显然应该得到同一个类的所有文本,然后我应该能够特别地按一个进行过滤,但是我总是用FindAll方法得到一个响应错误,当然我做错了。 这是我目前的代码:
site3 = 'https://ec.europa.eu/eurostat/news/news-releases'
harware3 = {'User-Agent': 'Mozilla/5.0'}
request3 = Request(site3,headers=harware3)
page3 = urlopen(request3)
soup3 = BeautifulSoup(page3, 'html.parser')
informes = soup3.findAll('div',{"class": "product-title"}).text
for 1 in informes:
print(1['href'])
代码中有几个错误,主要错误是
ResultSet
类型没有.text
属性另外
1
在Python中不是有效的变量名,请将其更改为例如i
:印刷品:
编辑:要获取链接的文本,请执行以下操作:
印刷品:
相关问题 更多 >
编程相关推荐