python - 从字符串中剪切特定部分,删除 HTML 标签。[网页抓取]
问题描述
我得到如下结果:
<a class="ellipsis" href="https://www.link.com" title="Name of the hyperlink ">Name of the hyperlink </a>
我只想提取一个变量 ex 的链接。链接,以及另一个前任的名称。姓名。到目前为止,这是我的代码。
def supa(linko):
r = get(linko, headers=ua)
return BeautifulSoup(r.content, 'html.parser')
soup = supa(base_url + search)
the_icons = soup.find_all('div', class_='caption')
for icon in the_icons:
name = icon.find('a', class_='ellipsis')
print(name)
解决方案
您可以在 find 末尾添加['href'] :
for icon in the_icons:
name = icon.find('a', class_='ellipsis')['href']
推荐阅读
- mysql - 插入 Base64Encoded 字符串返回不正确的字符串值(MySQL)
- java - Spring Boot: spring.profiles.active=dev/test/prod
- java - java.lang.IllegalArgumentException:用户名不能为空或空,AbstractXMPPConnection.java:484
- docker - 如何通过 docker RUN 运行复制命令
- c++ - 将浮点数转换为字符串时如何加速此代码?
- android - 如何在运行时直接(无动画)设置 FAB 图标旋转和颜色以及 FAB 背景?
- php - 带有 laravel 项目的 Css 不起作用(布局使用)
- javascript - Lodash 从选定的键创建新数组
- html - HTML:将表格中的两列设置为比其他列宽固定像素数
- javascript - 类型错误
javascript错误