我不知道如何在我的代码上获得不同的URL值。 你能帮我解决这个问题吗
代码:
import bs4 as bs
import urllib.request
sauce = urllib.request.urlopen('https://cointelegraph.com/tags/bitcoin').read()
soup = bs.BeautifulSoup(sauce, 'lxml')
for div in soup.find_all('div', class_='post-preview-item-inline'):
title = div.find(class_='post-preview-item-inline__title')
print(title.text)
body = div.find(class_='post-preview-item-inline__text')
print(body.text)
for link in div.select('a'):
print(link.get('href'))
结果:
Why Bitcoin Price Is Headed to 7-Month Low If $7K Support Fails
Bitcoin price continues to yield to bears and could collapse to $6.5K or below if $7,080 and $6,800 fail to hold as support.
https://cointelegraph.com/news/why-bitcoin-price-is-headed-to-7-month-low-if-7k-support-fails
https://cointelegraph.com/news/why-bitcoin-price-is-headed-to-7-month-low-if-7k-support-fails
javascript:void(0);
目标:
我只想显示一个网址,而不是2显示在结果上面。
我也想知道如何删除javascript:void(0);
谢谢
您正在使用
.select
,它允许css选择器。就像在css中一样,您可以通过以下方式选择具有适当类的特定链接:相关问题 更多 >
编程相关推荐