我想從美國內核俱樂部(https://www.akc.org/reg/dogreg_stats.cfm)刮取數據,我一直有一些麻煩。我指的是this stackoverflow post,我可以獲得第二張桌子上的所有行,但我無法格式化它們。如何用美麗的湯從AKC狗註冊網站刮取數據?
所以這裏是我的代碼。
from bs4 import BeautifulSoup
import requests
url = https://www.akc.org/reg/dogreg_stats.cfm
r. requests.get(r)
data= r.text
soup = BeautifulSoup(data)
rows = soup.find_all('table')[1].find_all('tr')
for row in rows:
cells = soup.find_all('td')
firstRanking = cell[1].get_text()
print(firstRanking)
所有它打印出來是
More on Registration Trends:
More on Registration Trends:
More on Registration Trends:
More on Registration Trends:
More on Registration Trends:
More on Registration Trends:
More on Registration Trends:
而不是實際的排名。
太感謝你了! – 2014-09-26 06:27:43