【发布时间】:2019-11-10 20:11:35
【问题描述】:
我正在尝试使用漂亮的汤和 Python/Pandas 从维基百科页面中提取所有“感兴趣的地方”,并将它们放入数据框中。例如:
https://en.wikipedia.org/wiki/1st_arrondissement_of_Paris
url_Paris_01 = requests.get('https://en.wikipedia.org/wiki/1st_arrondissement_of_Paris').text
soup_Paris_01 = BeautifulSoup(url_Paris_01, "html.parser")
for headline in soup_Paris_01.find_all("span", {"class": "mw-headline"}):
print(headline.text)
Geography
Demography
Historical population
Immigration
Quarters
Economy
Education
Map
Cityscape
**Places of interest**
Bridges
Streets and squares
See also
References
External links
没用
soup_Paris_01.find_all('li',attrs={"id":"Places_of_interest"})
我看到我的“名胜古迹”都有一个标题标签。
名胜古迹
【问题讨论】:
-
您之前问了几个问题并得到了有用的答案,但您没有接受任何一个,为什么?
-
嗨。我是stackoverflow的新手。我不确定如何接受他们。我现在就去做。
-
类似soup_Paris_01.find_all('li', {'class': None}, {'id':'Places_of_interest'}) 的东西有效,但我现在想根据维基百科页面限制我的结果而且“Places_of_interest”也不准确(包含),因为一些维基页面有“Places_of_interest in the arrondissement”
标签: html pandas web-scraping beautifulsoup