简体   繁体   中英

BeautifulSoup only returning first table row

I am trying to scrape a table from this webpage.

So far, I can access the page, click the search button with mechanize, but run into a problem when I start parsing the html with beautifulsoup. My code is:

url = 'http://forestsclearance.nic.in/Wildnew_Online_Status_New.aspx'               
br = mechanize.Browser()
br.open(url)
br.select_form(name='aspnetForm')
page = br.submit(id='ctl00_ContentPlaceHolder1_Button1')
soup = BeautifulSoup(page, 'html.parser')
table = soup.findAll("table", {"id" : "ctl00_ContentPlaceHolder1_tbl"})
print table

If you look in the HTML, the table I want has the id in the dictionary, but this prints only the html of the first row. I've tried finding the div tag, using findChildren() but it always returns the first row. Does someone know why this is happening and how I can grab the full table? Thanks

You have to findAll tr tags, see the code below.

url = 'http://forestsclearance.nic.in/Wildnew_Online_Status_New.aspx'               
br = mechanize.Browser()
br.open(url)
br.select_form(name='aspnetForm')
page = br.submit(id='ctl00_ContentPlaceHolder1_Button1')
soup = BeautifulSoup(page, 'html.parser')
table = soup.findAll('tr')
print table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM