我正在编写一个代码来打开一个网页并与之交互。我正在使用pydev中的mechanize模块。到目前为止,我写的代码如下:
from bs4 import BeautifulSoup
from mechanize import Browser
from mechanize import HTTPError
import re
def main():
movie='The Incredibles';
movie_search='+'.join(movie.split());
base_url= 'http://www.imdb.com/find?q=';
final_url=base_url+movie_search+'&s=all';
br=Browser();
br.open(final_url);
link=br.find_link(url_regex=re.compile(r'/title/tt.*'));
dest=br.follow_link(link);
print(link);
if __name__=="__main__":main()编译时,我得到以下错误:
Traceback (most recent call last):
File "D:\python\foldersorter\src\search.py", line 7, in <module>
from mechanize import Browser
File "C:\Python34\lib\site-packages\mechanize\__init__.py", line 122, in <module>
from _mechanize import \
File "C:\Python34\Lib\site-packages\mechanize\_mechanize.py", line 231
except urllib2.HTTPError, error:
^
SyntaxError: invalid syntax我找不到的语法错误到底是什么。我正在使用python 3.4。我是不是做错了什么?
发布于 2016-04-04 01:27:43
我认为你需要Python2来运行机械化,并且你正在尝试用Python3(文件"C:\Python34\Lib...)来运行它。
我希望对你有所帮助。
https://stackoverflow.com/questions/36388565
复制相似问题