ubuntu16.04 python3 爬虫

1、python3 与selenium 问题

    首先在命令栏使用pip命令安装selenium: pips install selenium ,若报权限问题则使用 sudo 安装 

    ubuntu自带Firefox浏览器,但是版本过高,需要使用geckodriver , 然后将解压后的文件复制到系统bin路径下 /usr/local/bin/

    geckodriver 链接:https://pan.baidu.com/s/1rEAFwRJ5lw0d3-zvQ1jTqQ

    import HTMLRunner 问题:

        将HTMLRunner.py复制到 /usr/local/lib/python3.5/dist-packages/下

        链接:https://pan.baidu.com/s/1naqChBQ3DmoSa7CapvRrjw

        HTMLRunner.py 是 python2 版本的,若想在python3中使用,需要进行修改,在修改过程中换行、空格等不要改变原来格式

        修改1:

        ImportError: No module named StringIO,StringIO 是python2模块,python3 没有

        第94行,改成import io

        第539行,改成self.outputBuffer = io.BytesIO()

        修改2:

        AttributeError: 'dict' object has no attribute 'has_key'

        第642行,if not rmap.has_key(cls): 改成 if not cls in rmap: 

        修改3:

        'str' object has no attribute 'decode'

        python3中对字符串操作没有decode, 则暂时不做decode操作

        第772行,改成ue=e

        第766行,uo=o.decode('latin-1') #暂时先不改

        修改4:

        TypeError: can't concat bytes to str

        bytes 与 str 不能直接连接,可以尝试都改成str

        第778行,改为output = saxutils.escape(str(uo)+ue)

        修改5:

        print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)
        TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and 'RPCProxy'

        第631行,改成 print (sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)) 
 

猜你喜欢

转载自blog.csdn.net/weixin_40071272/article/details/84964967