我正在尝试将维基百科作为一个项目来学习一些Python 3。我已经设法从页面获取链接:
import urllib.request
from bs4 import BeautifulSoup
html_code = urllib.request.urlopen('https://en.wikipedia.org/wiki/Category:Lists_of_airports_by_country').read().decode()
souped_code = BeautifulSoup(html_code, "html.parser")
for element in souped_code.find_all("a"):
dest_links = element.get('href')
print(dest_links)
但我只是得到一系列我想要使用的字符串(例如在列表中,这样可以使用索引并只保留“List_of_airports_in_”链接)并对它们进行过滤、打开、迭代等,但我只能我不知道如何实现这一点,因为它似乎会产生一系列字符串。
任何见解将不胜感激!
幕布斯7119047
相关分类