我想隔離位置列,然後最終得到它輸出到數據庫文件。我的代碼如下:試圖隔離1列美麗的湯
import urllib
import urllib2
from bs4 import BeautifulSoup
url = "http://en.wikipedia.org/wiki/List_of_ongoing_armed_conflicts"
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
trs = soup.find_all('td')
for tr in trs:
for link in tr.find_all('a'):
fulllink = link.get ('href')
tds = tr.find_all("tr")
location = str(tds[3].get_text())
print location
但我總是得到2個錯誤之一,或者列表超出範圍或退出代碼'0'。我不確定beautfulsoup,因爲我正在努力學習它,所以任何幫助表示感謝,謝謝!