Python Beautifulsoup Grab Table
I'm trying to grab the table out of this webpage. I'm not sure if I'm grabbing the right tags. Here is what I have so far. from bs4 import BeautifulSoup import requests page='http
Solution 1:
The table you need is in the iframe
that is loaded from a different URL.
Here's how you can grab it (watch the URL is different):
from bs4 import BeautifulSoup
import requests
page ='http://www.airchina.com.cn/www/jsp/airlines_operating_data/exlshow_en.jsp'
r = requests.get(page)
soup = BeautifulSoup(r.text)
div = soup.find('div', class_='mainRight').find_all('div')[1]
table= div.find('table', recursive=False)
forrowin table.find_all('tr', recursive=False):
for cell inrow('td', recursive=False):
print cell.text.strip()
prints:
Feb 2014%changevsFeb2013%changevsJan2014CumulativeFeb2014%cumulativechange1.Traffic1.RTKs(inmillions)1407.8...
Note that you need to use recursive=False
due to the nested tables on the page.
Post a Comment for "Python Beautifulsoup Grab Table"