python-3.x - 仅从使用 selenium python 的文章中获得第一段(需要所有段落)
问题描述
我想从这篇文章中提取所有段落,但我设法只使用 selenium for python 获得了第一段。文章链接为: https ://nthqibord.com/2019/08/15/pemimpin-pkr-pertahan-tun-mahathir/
我这样做是为了练习,但无法提取整篇文章。
我已经尝试了下面的代码来提取段落的确切部分:
post = driver.find_element_by_xpath("//div[@class='td-ss-main-content']/div[@class='td-post-content']//p")
结果只得到了第一段。我需要所有的段落。
解决方案
list = [p.text for p in self.driver.find_elements_by_xpath("//div[@class='td-ss-main-content']/div[@class='td-post-content']//p")]
paragraphs = "\n ".join(map(str, list))
推荐阅读
- c++ - Jeopardy Dice 在用户和计算机都离开后显示总回合数的问题
- python - 使用 *args 将毕达哥拉斯定理推广到 n 个事物
- javascript - setInterval 不会调用函数
- google-sheets - Google 表格查询给出错误“无法解析函数查询参数 2 的查询字符串:NO_COLUMN:Al”
- java - 第一次启动 API、spark-java 和 elasticsearch
- ember.js - Ember.js 中使用的“@”符号是什么?
- android - Firebase 警告 settings.crashlytics.com 请求的响应时间很慢
- python - 从scrapy中的POST请求下载文件
- kotlin - Kotlin 不一致地生成 SAM 存根
- sql-server - 将默认 GUID 值插入表列