微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Robot Framework 使用空格调用 add_argument

如何解决Robot Framework 使用空格调用 add_argument

为了设置机器人框架使用的浏览器的自定义用户代理,我找到了所有可以设置的地方:

User agent with spaces

但是 add_argument User 的值没有被转义,它在浏览器中添加了不需要的错误标签

enter image description here

whatismybrowser.com 检测到的用户代理是 User agent with spaces

我的问题很简单,如何传递带有空格的参数值?

我试过了:

  • User\ agent\ with\ spaces
  • User\\ agent\\ with\\ spaces
  • User${SPACE}agent${SPACE}with${SPACE}spaces
  • User\${SPACE}agent\${SPACE}with\${SPACE}spaces
  • "User agent with spaces"
  • 'User agent with spaces'
  • from collections import Counter data = [ {'br' : 'Kadek','mnt' : '2020-10','vl' : 30},{'br' : 'Kadek','vl' : 40},'vl' : 20},{'br' : 'Dede','mnt' : '2020-5',] cnt = Counter() for i in data: cnt[i['br'],i['mnt']] += i['value'] result = ([{'br': k[0],'mnt': k[1],'value': v} for k,v in cnt.items()]) print(result)

这些都不起作用...

解决方法

我已经找到了问题的根本原因。

在深入了解我的问题时,我发现这个问题也正是我遇到的问题:add_argument for user agent cuts off at first space

我在这里使用了机器人框架 docker 镜像:https://github.com/ppodgorsek/docker-robot-framework

二进制启动器 bin/chromium-browser.sh 包含未加引号的 bash 位置参数运算符:

#!/bin/sh

exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox $@

用带引号的位置参数运算符替换它可以解决问题,我可以设置受控浏览器的自定义用户代理。

#!/bin/sh

exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox "$@"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。