try和except的语法错误

时间:2013-07-02 16:53:01

标签: python exception syntax

我第一次尝试使用此程序:

def ScienceSearch():
query = SearchTerm.get()
address = ("http://www.google.com/search?q=%s&num=100&hl=en&start=0" % (urllib.quote_plus(query)))
request = urllib2.Request(address, None, {'User-Agent':'Mosilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'})
urlfile = urllib2.urlopen(request)

page = urlfile.read()
soup = BeautifulSoup(page)
QuerySplit = query.split()
print QuerySplit
QSL = len(QuerySplit)
print str(query)
string = ("")
j = 0
l=0

linkdictionary = {}
try:
    for li in soup.findAll('li', attrs={'class':'g'}):
        sLink = li.find('a')
        URL = sLink['href']
        print URL
        ourUrl = opener.open(URL).read()
        j =j + 1
        soup = BeautifulSoup(ourUrl)
        dem = soup.findAll('p')

excpept SearchError, e:
    print "Search failed: %s" % e

除非作为无效错误,否则标记。我应该纠正什么?的 _ __ _ __ _

1 个答案:

答案 0 :(得分:1)

你有一个拼写错误:excpept。它应该是except