爬虫笔记:SyntaxError: invalid syntax错误

写爬虫的时候,遇到了SyntaxError: invalid syntax错误。

   file_path = ('{0}/{1}.{2}'.format(os.getcwd(), md5(content).hexdigest(), 'jpg')
    if not os.path.exists(file_path):
        with open(file_path, 'wb') as f:
        f.write(content)
        f.close()

输出:

 File "/Users/pasca/PycharmProjects/crawler/toutiao-image-ajax/spider.py", line 100
    if not os.path.exists(file_path):
                                    ^
SyntaxError: invalid syntax

原因:python的语法错误,这里我是 file_path = (’{0}/{1}.{2}’.format(os.getcwd(), md5(content).hexdigest(), ‘jpg’)
多了( 导致的。
出现这种原因,还可能是缩进问题

猜你喜欢

转载自blog.csdn.net/qinglianchen0851/article/details/83828514