2012-06-25 2 views
1

어떻게해야할지 모르겠습니다. 39 행의 Python 스크립트가 있는데, 40 행에서 오류가 발생합니다! :(오류 :.존재하지 않는 라인 Python에 오류가 발생했습니다

Traceback (most recent call last): 
File "C:\Mass Storage\pythonscripts\Internet\execute.py", line 2, in <module> 
execfile("firstrunSoup.py") 
File "firstrunSoup.py", line 40 

           ^
SyntaxError: invalid syntax 

C:\Mass Storage\pythonscripts\Internet> 

그리고 여기 내 파이썬 코드입니다 :

###firstrunSoup.py### 
FILE = open("startURL","r") #Grab from 
stURL = FILE.read() #Read first line 
FILE.close() #Close 
file2save = "index.txt" #File to save URLs to 

jscriptV = "not" 
try: 
    #Returns true/false for absolute 
    def is_absolute(url): 
     return bool(urlparse.urlparse(url).scheme) 

    #Imports 
    import urllib2,sys,time,re,urlparse 
    from bs4 import BeautifulSoup 

    cpURL = urllib2.urlopen(stURL) #Human-readable to computer-usable 
    soup = BeautifulSoup(cpURL) #Defines soup 

    FILE = open(file2save,"a") 
    for link in soup.find_all('a'): #Find all anchor tags 
     outPut = "" 
     checkVar = link.get('href') #Puts href into string 
     if (checkVar is not None) and (checkVar != ""): #Checks if defined 
      if len(checkVar) > 11: #Check if longer than 11 characters 
       if checkVar[:11] != "javascript:": #Check if first 11 are "javascript:" 
        if checkVar[:7] != "mailto:": #Check if first 7 are "mailto:" 
         jscriptV = "not" 
        else: jscriptV = "" 
       else: jscriptV = "" 
      if checkVar != "#" and checkVar != "/": 
       if jscriptV == "not": 
        if checkVar is not None: #Checks if defined 
         if is_absolute(checkVar): outPut = checkVar.split("#")[0] 
         else: outPut = urlparse.urljoin(stURL,checkVar).split("#")[0] 
        if outPut != "": 
         print outPut 
         FILE.write(outPut + "\r\n") 
         FILE.close() 
execfile("nextrunsSoup.py") 

당신이 나를 도울 수 있다면, 제발 내가 지금까지에 많은 시간을 보냈는데, 마침내 준비가되면, 나는

답변

10

당신이 당신의 시도 때문에 파일의 몸 try:에 싸여

+0

정말 감사합니다 라인 전에 except 블록이 있어야합니다, 여러분! :) – Andrey

1

을 제외하고 일치를 필요 없다! 미리. 감사이를 얻고, 어디입니다210 또는 finally:?

2

try

execfile("nextrunsSoup.py") 
관련 문제