在这个错误出现之前,我已经设法解决了这些错误,并且我已经完全按照章节中的说明复制了代码,但是我发现这个错误被抛出,我似乎无法修复它:
File "xkcd.py", line 34
continue
^
SyntaxError: 'continue' not properly in loop.
这是我的代码:
comicElem = soup.select('#comic img')
if comicElem == []:
print('could not find comic image.')
else:
try:
comicUrl = 'http:' + comicElem[0].get('src')
# Download the image.
print('Downloading image %s...' % (comicUrl))
res = requests.get(comicUrl)
res.raise_for_status()
except requests.exceptions.MissingSchema:
# skip this comic
prevLink = soup.select('a[rel="prev"]')[0]
url = 'http://xkcd.com' + prevLink.get('href')
continue
我理解显而易见的错误,因为错误是非常清楚的,但是作为一个从网站直接复制代码的新手,我以前没有遇到过这种事情,我很难理解问题到底在哪里。在
continue应该在循环内部使用(for,while)。你的代码中没有循环。在
相关问题 更多 >
编程相关推荐