python - 如何从该页面的表格中抓取文本?
问题描述
我正在尝试使用and从此页面上的单词列表中刮取单词及其含义,尽管我不确定在从方法中获取表格 html 后如何循环遍历and标记:bs4
selenium
<tr>
<td>
bs4
find_all
from selenium import webdriver
from bs4 import BeautifulSoup
root = "https://www.graduateshotline.com/gre-word-list.html"
driver.get(root)
content = driver.page_source
soup = BeautifulSoup(content,'html.parser')
table = soup.find_all('table',attrs={'class': 'tablex border1'})[0]
现在在表变量中,我有整个表的 html,这是从开始到结束的片段:
<table class="tablex border1"> <tbody><tr><td><a href="https://gre.graduateshotline.com/a.pl?word=introspection" target="_blank">introspection</a></td>
<td>examining one's own thoughts and feelings</td></tr>
<tr><td><a href="https://gre.graduateshotline.com/a.pl?word=philanthropist" target="_blank">philanthropist</a></td>
.
.
.
<tr><td><a href="https://gre.graduateshotline.com/a.pl?word=refine" target="_blank">refine</a></td>
<td>make or become pure cultural </td></tr>
</tbody></table>
我不确定如何使用它访问单词及其含义。有任何想法吗?
解决方案
现在您的表格数据正在生成,您可以通过这种方式收集所需的数据。谢谢
import pandas as pd
import requests
link = 'https://www.graduateshotline.com/gre-word-list.html'
r = requests.get(link, headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'})
table_data = pd.read_html(r.text)
print(table_data)
推荐阅读
- ios - 当应用程序处于后台时,不会通过 FCM 调用 iOS 上的后台消息处理程序
- javascript - Formik 没有在屏幕上渲染任何东西
- node.js - 无法在 ubuntu 20.04 上通过 apt 安装 curl
- python - 我是编程的初学者,所以试图编写程序来“在 python 中转换数字”你能检查我下面的代码吗?
- python - 当我打印这个 python 代码时,只有第一个代码被执行。请帮我解决这个问题
- google-chrome - 除了'copy as cURL'中的数据,一个http请求可能携带什么数据?
- tabs - 是否可以在点击打开时自动运行 iTerm2 脚本
- java - POI excel跳过第一行
- python - 根据键值合并两个字典列表
- architecture - 使用rabbitmq队列处理微服务之间的实时数据同步