python - 如何从这个网页抓取的 HTML 中提取某些元素
问题描述
这是我抓取的 HTML。如何提取名为“我要提取的代码”的文本,然后将其保存为字符串“作者”?提前致谢!
<a class="lead-author-profile-link" href="https://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=2994282" target="_blank" title="View other papers by this author"><span>Code I want to Extract</span><i aria-hidden="true" class="icon icon-gizmo-navigate-right"></i></a>
解决方案
你可以试试看:
html_doc="""
<a class="lead-author-profile-link" href="https://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=2994282" target="_blank" title="View other papers by this author"><span>Code I want to Extract</span><i aria-hidden="true" class="icon icon-gizmo-navigate-right"></i></a>
"""
soup = BeautifulSoup(html_doc, 'lxml')
author = soup.find('a').text
print(author)
输出将是:
Code I want to Extract
推荐阅读
- macos - Puppeteer - 停止将 Chromium 放在前面
- oracle - ORACLE APEX 报告模板中的可单击 DIV 不起作用
- linux - [Odoo][Odoov13] 使用 selenium 运行方法
- python - 如何将一个矩阵插入另一个矩阵
- python-3.x - TensorFlow 找不到 GPU
- php - Oauth 签名生成器故障
- python - 在使用 qtdesigner 创建的小部件上使用 PyCharm 自动完成
- tensorflow - 在 tensorflow 中加载 coco 关键点数据集
- python - 从 ModelSerializer 类中获取字段名称列表
- javascript - Fullcalendar 4.3 为背景事件添加标题