我试图从我的靓汤搜索中提取“信息技术”作为输出。但我还没弄清楚,因为“扇区”是URL中任何一种股票代码的动态值。你知道吗
有人能告诉我如何提取这些信息吗?你知道吗
<a href="http://eresearch.fidelity.com/eresearch/markets_sectors/sectors/sectors_in_market.jhtml?tab=learn&sector=45">Information Technology</a>
我的代码:
url = 'https://eresearch.fidelity.com/eresearch/goto/evaluate/snapshot.jhtml?symbols=AAPL'
html = requests.get(url).text
detail_tags_sector = BeautifulSoup(html, 'lxml')
detail_tags_sector.find_all('a')
要从锚元素获取文本,需要访问每个锚元素上的.text变量
因此,您的代码将更改为:
这些答案的问题在于,它们收集了页面上所有链接的文本,并且有相当多的链接。如果只选择
information technology
字符串,则只需添加:输出:
您可以使用以下任一选项。你知道吗
或者
或者
如果有帮助请告诉我。你知道吗
相关问题 更多 >
编程相关推荐