使用 BeautifulSoup FindAll 进行网页抓取

Webscraping with BeautifulSoup FindAll

我想在以下网站下载需要了解的上面 4 篇文章的 hrefs:

http://www.marketwatch.com/

但我无法用 FindAll 唯一地识别它们。以下方法为我提供了同样符合这些标准的文章,以及其他一些文章。

trend_articles  = soup1.findAll("a", {"class": "link"})
href= article.a["href"]

trend_articles  = soup1.findAll("div", {"class": "content--secondary"})
href= article.a["href"]

有没有人有什么建议,我怎样才能得到那 4 篇文章,而且只有那 4 篇文章?

它似乎对我有用:

from bs4 import BeautifulSoup
import requests

page = requests.get("http://www.marketwatch.com/").content
soup = BeautifulSoup(page, 'lxml')
header_secondare = soup.find('header', {'class': 'header--secondary'})
trend_articles = header_secondare.find_next_siblings('div', {'class': 'group group--list '})[0].findAll('a')

trend_articles = [article.contents[0] for article in trend_articles]
print(trend_articles)