python - 需要去除过滤后的解析 HTML 链接中的标签
问题描述
从众多链接中选择一个所需链接后,需要进一步将此链接传递给aDataFrame
以提取数字。
我的代码如下:
response=requests.get(url)
soup=BeautifulSoup(response.content,"html.parser")
tags=soup.select_one(a[href*=mar]') *** Out of Jan, Feb and Mar links, the line filters for a link that has Mar in it.
现在我得到“'a href="http://someurl.xlsx">March (12kb, Excel)”'
我只需要“ http://someurl.xlsx ”来传递给aDataFrame
以读取Excel 页面的内容。
解决方案
尝试以下
from bs4 import BeautifulSoup
html = '<a href="http://someurl.xlsx">March (12kb, Excel)</a>'
soup = BeautifulSoup(html, features="lxml")
tags = soup.select('a')[0].get('href')
print(tags)
http://someurl.xlsx
推荐阅读
- sql - 如何优化我的 varchar(max) 列?
- angular - 根据json文件路由到动态位置
- c - 添加到链表时,节点地址一直相互覆盖
- c++ - 仅当使用 VisualStudio 制作的文件夹时,日志文件才会保持为空。使用的低级 io
- java - 有人可以帮我理解 ImageIcon 如何适用于 java 吗?
- python - SQLAlchemy 中的条件过滤
- .net - MVC 验证在提交前显示错误消息
- r - 要创建一个循环或函数来收集使用 r 中另一个数据帧中的数据帧中的其他列值计算的多个向量的值?
- android - 我对如何在重新启动应用程序后使用 sharedpreferences 来保留我的卡片视图状态感到困惑?如果可能,请建议一些代码
- python - 如何让爬虫运行 n 次,停止并等待 10 分钟,然后再次运行它 n 次并重复整个过程?