>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
except Exception, e:
^
SyntaxError: invalid syntax
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
print 'Error:', e
^
SyntaxError: Missing parentheses in call to 'print'
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
print() 'Error:', e
^
SyntaxError: invalid syntax
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
print 'Error:', e
^
SyntaxError: Missing parentheses in call to 'print'
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
print '%s: %s' % result
^
SyntaxError: Missing parentheses in call to 'print'
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line
print 'Usage: %s url1 [url2 url3 ...]' % sys.argv[]
^
SyntaxError: Missing parentheses in call to 'print'
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line , in <module>
File "/usr/local/python3/lib/python3.5/site-packages/builtwith/__init__.py", line , in <module>
import urllib2
ImportError: No module named 'urllib2'
因为Python2中的Exception,e 的写法不再支持,需要修改成Exception as e.
(这句话看了我半天, 明明说是抛出了Exception e, 却硬是没看到e的信息,火大!)
另外Python2中的print语句在Python3中需要写成print(),按照错误提示修改对应行数即可。
语法问题修改之后,会报一个没有安装urllib2的包的错误。
通过pip install urllib2也会提示找不到包。
这是因为builtwith依赖于urllib2包。但Pyhton2中的urllib2工具包,在Python3中分拆成了urllib.request和urllib.error两个包。就导致找不到包,同时也没办法安装。
所以需要install urllib.request和install urllib.error 两个包,然后将builtwith包中的import urllib2修改为import urllib.request 和import urllib.error。
同时代码中的方法函数也需要修改,基本就是将urllib2.xxx修改为urllib.request.xxx。
urllib2修改后对应的函数列表见:https://docs.python.org/2/library/urllib2.html。