ubuntu16.04 python 爬虫

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)) 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值