python - 为什么内部标签中的文本被忽略,如何解决?
问题描述
<p>The latest media Tweets from Yohir Akerman (@yohirakerman). My bio changes all the time. /// akermancolumnista<strong>@gmail.com</strong>. Airplane</p>
我尝试提取整个文本如下:
body = response.xpath('//*[@id="b_results"]/p/text()").getall()
print(body)
我得到的输出是:
['The latest media Tweets from Yohir Akerman (@yohirakerman). My bio changes '
'all the time. /// akermancolumnista',
'. Airplane']
标签内的整个文本都<strong>
被忽略了,如何解决?
解决方案
不要使用text()
. 里面
body = response.xpath('//*[@id="b_results"]/p").getall()
print(body)
然后加入正文并清理所有标签的正文。
推荐阅读
- javascript - Javascript:检查数字数组以获取使数组连续所需的缺失数字数
- php - PHP 7:如何将新字段附加到 stdObject 但在特定位置?
- javascript - 将 JS 事件侦听器添加到 Chrome 扩展弹出窗口
- mysql - 如何完成这个查询功能?
- arduino - 带有 Arduino Uno R3 开关控制的操纵杆将不显示开关按钮
- amazon-web-services - 在 Cognito 中查找用户名
- python - 在迭代 for 循环时出现生成器的问题
- airflow - 如果分支不收敛,气流能否在 dag 中运行分支任务?
- excel - 如何获得一个公式 5 年的每日结果并将它们放在一个表格中?
- c++ - openmp 并行中的 std::lock_guard