300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python怎样读取网页中的文本_如何使用python和selenium读取HTML表格单元格中的文本?...

python怎样读取网页中的文本_如何使用python和selenium读取HTML表格单元格中的文本?...

时间:2024-04-27 01:16:56

相关推荐

python怎样读取网页中的文本_如何使用python和selenium读取HTML表格单元格中的文本?...

根据您尝试访问的网站,您可能不需要使用硒。您可以使用requests访问html。在

对于您给出的HTML,uou可以使用BeautifulSoup提取表信息,如下所示:from bs4 import BeautifulSoup

html = """

Col 1 Col 2 Col 3 Hello A number Another number there A number Another number """

soup = BeautifulSoup(html, "html.parser")

rows = []

for tr in soup.find_all('tr'):

cols = []

for td in tr.find_all(['td', 'th']):

td_text = td.get_text(strip=True)

if len(td_text):

cols.append(td_text)

rows.append(cols)

print rows

给你rows保持:

^{pr2}$

要使用requests,它将启动如下内容:import requests

response = requests.get(url)

html = response.text

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。