我使用以下代码:
from bs4 import BeautifulSoup
soup = BeautifulSoup (open("43rd-congress.htm"))
final_link = soup.p.a
final_link.decompose()
trs = soup.find_all('tr')
for tr in trs:
for link in tr.find_all('a'):
fulllink = link.get ('href')
print fulllink #print in terminal to verify results
tds = tr.find_all("td")
try:
names = str(tds[0].get_text())
years = str(tds[1].get_text())
positions = str(tds[2].get_text())
parties = str(tds[3].get_text())
states = str(tds[4].get_text())
congress = tds[5].get_text()
except:
print "bad tr string"
continue
print names, years, positions, parties, states, congress
我得到以下错误:
SyntaxError: 'continue' not properly in loop.
为什么?我检查过压痕和冒号。提前谢谢你的帮助。
目前没有回答
相关问题 更多 >
编程相关推荐