Html 网页抓取:beautifulsoup

Html 网页抓取:beautifulsoup,html,pandas,web-scraping,beautifulsoup,Html,Pandas,Web Scraping,Beautifulsoup,我正在尝试使用beautiful soup和Python/Pandas从维基百科页面中提取所有“感兴趣的地方”,并将它们放入数据框架中。例如: 不起作用 soup_Paris_01.find_all('li',attrs={"id":"Places_of_interest"}) 我看到我的“名胜古迹”都有一个标题标签 名胜古迹 艺术中心首先在兴趣地点span标签下找到ul项目,然后对ul项目下的所有锚定标签进行查找() from bs4 import BeautifulSoup

我正在尝试使用beautiful soup和Python/Pandas从维基百科页面中提取所有“感兴趣的地方”,并将它们放入数据框架中。例如:



不起作用

soup_Paris_01.find_all('li',attrs={"id":"Places_of_interest"}) 
我看到我的“名胜古迹”都有一个标题标签

名胜古迹


  • 艺术中心
首先在
兴趣地点
span标签下找到
ul
项目,然后对
ul
项目下的所有锚定标签进行查找()

from bs4 import BeautifulSoup
import requests
url_Paris_01 = requests.get('https://en.wikipedia.org/wiki/1st_arrondissement_of_Paris').text
soup_Paris_01 = BeautifulSoup(url_Paris_01, "html.parser")
placeofinterset=soup_Paris_01.find("span",id="Places_of_interest").find_next('ul')
for place in placeofinterset.find_all('a'):
    print(place['title']) #This will give you title
    print(place.text) #This will give you text

首先在
ul
感兴趣的地点
span标签下找到
ul
项目,然后对
ul
项目下的所有锚定标签执行find_all()

from bs4 import BeautifulSoup
import requests
url_Paris_01 = requests.get('https://en.wikipedia.org/wiki/1st_arrondissement_of_Paris').text
soup_Paris_01 = BeautifulSoup(url_Paris_01, "html.parser")
placeofinterset=soup_Paris_01.find("span",id="Places_of_interest").find_next('ul')
for place in placeofinterset.find_all('a'):
    print(place['title']) #This will give you title
    print(place.text) #This will give you text

你以前问了几个问题,得到了有用的答案,但你没有接受任何问题,为什么?嗨。我是新来的。我不知道如何接受他们。我现在就去做。比如soup_Paris_01。find_all('li',{'class':None},{'id':'Places_of u interest'})有效,但我现在想限制我的结果,因为维基百科页面上的结果,而且'Places_of u interest'不准确(包含)因为一些维基页面上有“在该地区感兴趣的地方”,你以前问了几个问题,得到了有用的答案,但你没有接受任何一个,为什么?嗨。我是新来的。我不知道如何接受他们。我现在就去做。像soup_Paris_01。find_all('li',{'class':None},{'id':'Places_of u interest'})很有效,但我现在想根据维基百科页面限制我的结果,而且'Places_of u interest'不准确(包含),因为一些维基页面在区域中有'Places_of u interest''
from bs4 import BeautifulSoup
import requests
url_Paris_01 = requests.get('https://en.wikipedia.org/wiki/1st_arrondissement_of_Paris').text
soup_Paris_01 = BeautifulSoup(url_Paris_01, "html.parser")
placeofinterset=soup_Paris_01.find("span",id="Places_of_interest").find_next('ul')
for place in placeofinterset.find_all('a'):
    print(place['title']) #This will give you title
    print(place.text) #This will give you text