你好,这是我想从使用BeautifulSoup抓取第一个链接的代码。你知道吗
查看源:https://www.binance.com/en/blog
我想抓住这里的第一篇文章,所以它将是“信托钱包现在支持恒星流明,4个更多的代币”
我正在尝试使用Python来实现这一点。你知道吗
我用这个代码,但它抓住所有的链接,我只想第一个抓住
with open('binanceblog1.html', 'w') as article:
before13 = requests.get("https://www.binance.com/en/blog", headers=headers2)
data1b = before13.text
xsoup2 = BeautifulSoup(data1b, "lxml")
for div in xsoup2.findAll('div', attrs={'class':'title sc-0 iaymVT'}):
before_set13 = div.find('a')['href']
我该怎么做?你知道吗
当您发现满意的结果时,您可以评估循环和
break
中的情况。 你知道吗带有这些更改的代码输出: 你知道吗
目前我能想到的最简单的解决方案是使用
break
,这是因为findAll
对于第一个元素,可以使用
find
before_set13 = soup.find('div', attrs={'class':'title sc-62mpio-0 iIymVT'}).find('a')['href']
尝试(从“阅读更多”按钮中提取href)
相关问题 更多 >
编程相关推荐