I am trying to find a table in a Wikipedia page using BeautifulSoup and for some reason I don’t get the table. Can anyone tell why I don’t get the table?
my code:
import BeautifulSoup import requests url='https://en.wikipedia.org/wiki/List_of_National_Historic_Landmarks_in_Louisiana' r=requests.get(url) url=r.content soup = BeautifulSoup(url,'html.parser') tab=soup.find("table",{"class":"wikitable sortable jquery-tablesorter"}) print tab
prints: None
Advertisement
Answer
You shouldn’t use jquery-tablesorter
to select against in the response you get from requests because it is dynamically applied after the page loads. If you omit that, you should be good to go.
tab = soup.find("table",{"class":"wikitable sortable"})