gpt4 book ai didi

python - Python 不存在的行出错

转载 作者:太空宇宙 更新时间:2023-11-04 06:50:54 28 4
gpt4 key购买 nike

我不知道该怎么做,我有一个 39 行的 Python 脚本,它在第 40 行给我一个错误! :( 错误:

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>

这是我的 Python 代码:

###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")

如果你能帮助我,请帮助我。到目前为止,我已经在这上面花了很多时间,当它终于准备好时,我明白了。提前致谢!

最佳答案

你没有匹配,除了你的尝试

关于python - Python 不存在的行出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11194346/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com