python - 似乎无法在 BeautifulSoup 中将文本附加到标签
问题描述
我从网页中抓取了文本和 HTML 链接信息,并试图将其附加到<p>
标签上,但这不起作用。让我举例说明:
data = """
<div class="Answer">
1. BOUNDARIES - EPB & APL <i>(inferior)</i>, EPL <i>(superior). </i><div>2. FLOOR (proximal to distal) - radial styloid => scaphoid => trapezium => 1st MC base. <br /><div>3. CONTENTS - cutaneous branches of radial nerve <i>(on the roof),</i> cephalic vein <i>(begins here),</i> radial artery <i>(on the floor).</i></div></div><div><br /></div><div><img src="paste-27a44c801f0776d91f5f6a16a963bff67f0e8ef3.jpg" /><br /></div><div><b>Image: </b>Case courtesy of Dr Sachintha Hapugoda, <a href="https://radiopaedia.org/">Radiopaedia.org</a>. From the case <a href="https://radiopaedia.org/cases/52525">rID: 52525</a> [Accessed 15 Nov. 2018].</div>
</div>
"""
soup = BeautifulSoup(data, "html.parser")
image_link = soup.find('div').find('b').next.next
new_tag = soup.new_tag('p', image_link)
print(new_tag.append(image_link))
以上返回None
。我该怎么办?
解决方案
它应该是
new_tag = soup.new_tag('p')
new_tag.append(image_link)
print(new_tag)
推荐阅读
- android - MLKit 错误:无法从路径 mlkit_pose/pose_person_detector_f16.tflite 加载模型
- permissions - Avada Wordpress 主题 - 无法访问品牌设置
- c# - 如何通过创建一个空行来结束一个序列?
- applescript - 使用 AppleScript 将 finder 中的副本替换为脚本
- android - 使用 SpeechRecognizer API 对 editText 的语音输入进行 Espresso 测试
- python - 海王星插入数据很慢
- c# - 使用 getter 类在 C# 中解析嵌套的 JSON [Array]
- java - Java 对象引用数组初始化
- kubernetes - 为角色绑定修补命名空间和更改资源类型
- eclipse - Liferay 为多个 portlet 创建自定义 PanelCategory