Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用漂亮的布拉网_Python_Web Scraping_Findall - Fatal编程技术网

Python 用漂亮的布拉网

Python 用漂亮的布拉网,python,web-scraping,findall,Python,Web Scraping,Findall,我想在以下网站上下载上述4篇文章的HREF,这些文章是我需要知道的: 但我不能把他们和芬德尔区别开来。下面的方法为我提供了一些文章,还有一些其他的,也符合这些标准 trend_articles = soup1.findAll("a", {"class": "link"}) href= article.a["href"] trend_articles = soup1.findAll("div", {"class": "content--secondary"}) href= article.

我想在以下网站上下载上述4篇文章的HREF,这些文章是我需要知道的:

但我不能把他们和芬德尔区别开来。下面的方法为我提供了一些文章,还有一些其他的,也符合这些标准

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)

我找到了一条可能的路径,从顶部开始:trend_articles=soup1.findAll(“div”,“class”:“element2 element--article is lead”}),然后使用href=article.div.div.ul.li.a[“href”]但这会让我进入第一个ul,但我需要进入第二个ul。基本上,如果我能沿着树导航,那会很有帮助。哇,这看起来比我想做的简单多了。非常感谢你@尼可拉·塔塔塔利亚不客气!祝你好运!