18910140161

HTML-如何使用BeautifulSouple-Stack Overflow从网页上的特定部门提取链接

顺晟科技

2022-10-19 13:34:56

32

我对网页搜索是新手,对我目前的情况有点困惑。是否有一种方法从html检查器中提取这个网站(我用红色圈出的地方)的所有扇区的链接,它似乎是在“Performance-Section”类下,也在“Heading”类下。我的想法是从“performance-section”开始,最后到达“a”标记href以获得链接。

我尝试使用以下代码,但结果是“none”。我在这里停下来是因为如果我在得到“a”标记之前已经没有得到任何东西,那么我认为没有必要继续下去。

import requests
import urllib.request
from bs4 import BeautifulSoup
url = "https://eresearch.fidelity.com/eresearch/goto/markets_sectors/landing.jhtml"
response = requests.get(url)
results_page = BeautifulSoup(response.content,'lxml')
heading =results_page.find('performance-section',{'class':"heading"})

提前感谢!


顺晟科技:

您的头脑游戏是正确的。

问题

您应该再看一遍文档,因为目前您甚至不尝试选择标记,而是尝试混合类--这也是可能的,但要学会,您应该一步一步地开始。

获取及其

的解决方案

这将选择all in with类 父母与班级在一起

import requests
import urllib.request
from bs4 import BeautifulSoup
url = "https://eresearch.fidelity.com/eresearch/goto/markets_sectors/landing.jhtml"
response = requests.get(url)
results_page = BeautifulSoup(response.content,'lxml')
heading =results_page.find('performance-section',{'class':"heading"})

import requests
import urllib.request
from bs4 import BeautifulSoup
url = "https://eresearch.fidelity.com/eresearch/goto/markets_sectors/landing.jhtml"
response = requests.get(url)
results_page = BeautifulSoup(response.content,'lxml')
heading =results_page.find('performance-section',{'class':"heading"})
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航