2015-11-17 30 views
1

我正在嘗試使用BeautifulSoup在維基百科頁面中找到一張表格,出於某種原因,我沒有收到表格。 任何人都可以告訴我爲什麼我不拿桌子嗎?beautifulsoup-找到指定類別的表格

我的代碼:

import BeautifulSoup 

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 

打印:無

+0

你能明確指定你正在使用的模塊嗎? 'requests.get'從哪裏來? – DJJ

+0

@DJJ'requests.get'來自[請求庫](http://docs.python-requests.org/en/latest/) – Celeo

回答

3

你不應該使用jquery-tablesorter選擇針對您的請求得到,因爲它是在頁面加載後動態應用的響應。如果你忽略了這一點,你應該很好走。

tab = soup.find("table",{"class":"wikitable sortable"})