python - 尝试使用 BeautifulSoup 从 Wikipedia 中抓取参考链接,但我一直没有得到任何输出
问题描述
我正在尝试从 wiki 页面上抓取参考链接,但我一直得到 None 作为输出。
from bs4 import BeautifulSoup
import requests,lxml
webs=requests.get('https://en.wikipedia.org/wiki/Integrated_development_environment')
soup=BeautifulSoup(webs.content,'lxml')
links=soup.find('div', {'class':'reflist'})
print(links.get('href'))
解决方案
我用给定的维基百科页面测试了这段代码,它返回一个包含每个链接作为字符串的列表。
from bs4 import BeautifulSoup
import requests,lxml
webs=requests.get('https://en.wikipedia.org/wiki/Integrated_development_environment')
soup=BeautifulSoup(webs.content,'html.parser')
links=soup.find_all('a', class_ = 'external text', rel = 'nofollow')
map = map(str , links)
result = []
for link in map:
result.append(link[link.find('href=\"')+6:link.find('rel=')-2])
print(result)
推荐阅读
- java - 使用 java 加密库和 RSA 4096 PublicKey 的加密无法正常工作
- android - NPM 缓存步骤在 Azure DevOps 中不起作用
- arrays - 连接两个递增子数组的最大长度递增超级数组
- elasticsearch - simple_query_string 的弹性搜索问题
- typescript - Typescript 枚举作为参数类型允许无效值
- javascript - 根据 url 设置 src
- sql - 如何聚合一列位?
- python - 如何使用 plt.imshow(image) 显示多个图像?
- python - 有没有办法通过循环文件目录动态生成字典
- reactjs - findOne 没有特定元素的文档