Python BeautifulSoup从网页中抓取表格
我正试图从一个网页上抓取数据,该网页上有一个当前已登录到该网站的用户表Python BeautifulSoup从网页中抓取表格,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正试图从一个网页上抓取数据,该网页上有一个当前已登录到该网站的用户表 browser = RoboBrowser() loginURL = 'https://geico.aisreview.com/ais/admin.aspx' browser.open(loginURL) form = browser.get_form(id='form1') form['txtPWD'].value = 'myPassword' browser.submit_form(form) 我正在使用下面的代码登录
browser = RoboBrowser()
loginURL = 'https://geico.aisreview.com/ais/admin.aspx'
browser.open(loginURL)
form = browser.get_form(id='form1')
form['txtPWD'].value = 'myPassword'
browser.submit_form(form)
我正在使用下面的代码登录该网站
browser = RoboBrowser()
loginURL = 'https://geico.aisreview.com/ais/admin.aspx'
browser.open(loginURL)
form = browser.get_form(id='form1')
form['txtPWD'].value = 'myPassword'
browser.submit_form(form)
我用这段代码试图从表中提取数据。现在我只是想把它打印出来做测试
soup = BeautifulSoup(loginURL)
table = soup.find_all("table", {"class": "rgMasterTable"})
for myTable in table:
table_body = myTable.find('tbody')
try:
rows = table_body.find_all('tr')
for tr in rows:
cols = tr.find_all('td')
for td in cols:
print td.text
except:
print "no tbody found"
当运行代码时,我没有得到任何错误,但是没有输出任何内容。我能够确定从未输入for循环,但我不知道为什么。您可以使用从html读取表
import pandas as pd
import requests
loginURL='http://example.com'
res=requests.get(loginURL)
tables=pd.read_html(res.text) # return list of tables
print(tables)#will display all the tables, please slice the list for your required table.
或者您可以直接提供类似pd的url。read_htmloginURL我敢打赌您的表列表是空的。您可以打印表吗?哪个为循环?同时打印您正在迭代的变量。。。像printtable printrows``printcols@rahlf23我打印出的表格是空的,但在网站上,表格中有6行。