【发布时间】:2021-11-08 05:32:03
【问题描述】:
我希望从网站上抓取一些数据。作为序言,我是新手。我希望根据邮政编码专门过滤所有返回的 XML 数据(邮政编码在 'item_teaser' 下)。
<item lat="43.6437075296758" long="-80.083111524582" item_name="Acton Golf Club" item_url="http://www.ontariogolf.com/courses/acton/acton-gc/" item_teaser="4955 Dublin Line Acton, Ontario L7J 2M2"/>
以上是我尝试提取的示例,但我想通过特定邮政区域过滤所有内容(前 3 个字母,例如 L7J)
find_all()可以通过item_teaser找到“L7J、L2S、L2O等”相关的字符串吗?并返回那些匹配的邮政区域,包括整个项目?
下面的代码是错误的,因为我无法提取任何东西,但这是我目前所拥有的。
from bs4 import BeautifulSoup
url = "http://www.ontariogolf.com/app/map/cfeed.php?e=-63&w=-106&n=55&s=36"
xml = requests.get(url)
# I was just seeing if I could grab everything from the website which worked when I printed.
soup = BeautifulSoup(xml.content, 'lxml')
# I am trying to show all item teasers just to try it out, but I can't seem to figure it out
tag = soup.find_all(id="item_teaser")
print(tag)
【问题讨论】:
标签: python beautifulsoup findall