小编ale*_*cxe的帖子

pymongo默认数据库连接

我需要从我的Python代码连接到MongoDB,我唯一拥有的是一个url.每个mongo URL doc我可以指定数据库名称:

mongodb://host/db_name
Run Code Online (Sandbox Code Playgroud)

现在我想使用从URL指定的数据库,并且不想手动解析它以提取数据库的名称.但MongoClient没有访问默认界面的界面.有什么想法如何管理?

python mongodb pymongo

13
推荐指数
1
解决办法
5850
查看次数

在代理服务器后面运行selenium

我一直在使用selenium进行自动浏览器模拟和python中的web抓取,它对我来说效果很好.但现在,我必须在代理服务器后面运行它.因此,现在selenium打开窗口但由于未在打开的浏览器上设置代理设置而无法打开请求的页面.目前的代码如下(样本):

from selenium import webdriver

sel = webdriver.Firefox()
sel.get('http://www.google.com')
sel.title
sel.quit()
Run Code Online (Sandbox Code Playgroud)

如何更改上面的代码现在也可以使用代理服务器?

python proxy selenium web-scraping selenium-webdriver

13
推荐指数
2
解决办法
2万
查看次数

为什么factory_boy优于在测试中直接使用ORM?

我不明白为什么factory_boy比直接在Django测试中创建ORM /模型实例更受欢迎.factory_boy网站几乎无法解释使用它的好处.

作为固定装置的替代品是有意义的,这些固定装置难以管理,速度慢等.

但是,为什么不只是根据测试需要创建模型实例?

如果factory_boy完全取代了对db的写入,那么很好,我认为在这种情况下它会非常有用,但工厂男孩创建的django模型实例仍然与数据库交互.

另一个潜在的好处是对序列的支持,但是在不需要工厂男孩的情况下创建序列/样本数据并不困难.

总而言之,我看到使用工厂男孩几乎没有任何好处,直接创建对象/模型实例.

我希望我错过了一些明显的东西!

python testing django unit-testing factory-boy

13
推荐指数
1
解决办法
2191
查看次数

"npm isntall"命令存在

当您键入非法npm命令时,您将收到一条用户友好的错误消息,指出哪些命令合法使用:

$ npm illegal

Usage: npm <command>

where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, issues, la, link,
    list, ll, ln, login, ls, outdated, owner, pack, prefix,
    prune, publish, r, rb, rebuild, remove, repo, restart, rm,
    root, run-script, s, se, search, set, show, shrinkwrap,
    star, stars, start, stop, submodule, tag, test, tst, un, …
Run Code Online (Sandbox Code Playgroud)

javascript package-managers node.js npm

13
推荐指数
1
解决办法
1897
查看次数

selenium没有设置输入字段值

假设我们有这个网站https://www.coinichiwa.com/,它有一个BET AMOUNT输入框.它的HTML是:

<input autocomplete="off" id="betFa" name="a" maxlength="20" value="0.00000000" class="betinput" style="">
Run Code Online (Sandbox Code Playgroud)

我需要在其中添加一些价值.这是我的代码:

browser = webdriver.Firefox()
browser.get('https://www.coinichiwa.com')

browser.find_element_by_id("betFa").send_keys("0.00000005")
print browser.find_element_by_xpath("//input[contains(@id,'betFa')]").text
Run Code Online (Sandbox Code Playgroud)

但它既没有将它的值设置为"0.00000005",也没有打印value输入.

我不确定出了什么问题.你能建议吗?为什么它不起作用?

python selenium automation selenium-webdriver

13
推荐指数
1
解决办法
2万
查看次数

如何将bootstrap行分成5个相等的部分?

我想将bootstrap行分成5个相等的部分.它包括12-col-md,所以我如何将它分成相等的5个部分?

任何人都可以帮我解决这个问题吗?

html twitter-bootstrap

13
推荐指数
5
解决办法
4万
查看次数

在Protractor/WebDriverJS中拒绝了承诺

WebDriverJS和Protractor本身完全基于承诺的概念:

WebDriverJS(以及Protractor)API完全是异步的.所有功能都返回承诺.WebDriverJS维护一个待处理的承诺队列,称为控制流,以保持执行的有序性.

并且,根据定义:

promise是一个表示值的对象,或者是值的最终计算.每个承诺都以挂起状态开始,可以使用值成功解析,也可以拒绝指定错误.

关于承诺拒绝的最后一部分是我不完全理解并且未在Protractor中处理过的事情.我们看到和编写的一种常见模式是使用then()并为成功解决的承诺提供功能:

element(by.css("#myid")).getAttribute("value").then(function (value) {
    // do smth with the value
});
Run Code Online (Sandbox Code Playgroud)

问题:

是否有可能由任何Protractor/WebDriverJS函数返回的承诺无法成功解决并被拒绝?我们真的应该担心并处理它吗?

javascript testing selenium promise protractor

13
推荐指数
1
解决办法
2144
查看次数

jasmine.matchersUtil.equals vs ===

我们开发了一套相当大的自定义茉莉花匹配器,有助于使我们的代码更清晰,避免代码重复.我注意到一些自定义茉莉花匹配器使用了===相等测试和一些jasmine.matchersUtil.equals.例:

toHaveHandCursor: function() {
    return {
        compare: function(actual) {
            return {
                pass: actual.getCssValue("cursor").then(function(cursor) {
                    return cursor === "pointer";
                })
            };
        }
    };
},

toBeActive: function() {
    return {
        compare: function(elm) {
            return {
                pass: protractor.promise.all([
                    elm.getId(),
                    browser.driver.switchTo().activeElement().getId()
                ]).then(helpers.spread(function (currentElementID, activeElementID) {
                    return jasmine.matchersUtil.equals(currentElementID, activeElementID);
                })),
                message: "Element is not active."
            };
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

问题:

jasmine.matchersUtil.equals===平等测试有什么区别,哪种方法应该首选?

换句话说,一般来说,如果我们只使用,我们会冒风险===吗?

javascript testing selenium selenium-webdriver protractor

13
推荐指数
1
解决办法
534
查看次数

beautifulsoup:find_all on bs4.element.ResultSet对象还是列表?

嗨所以我在a上应用find_all beautifulsoup object,并找到一些东西,这是一个bs4.element.ResultSet object或一个list.

我想在那里进一步做find_all,但是不允许这样做 bs4.element.ResultSet object.我可以循环遍历bs4.element.ResultSet objectfind_all的每个元素.但是我可以避免循环并将其转换回来beautifulsoup object吗?

请参阅代码了解详情.谢谢

html_1 = """
<table>
    <thead>
        <tr class="myClass">
            <th>A</th>
            <th>B</th>
            <th>C</th>
            <th>D</th>
        </tr>
    </thead>
</table>
"""
soup = BeautifulSoup(html_1, 'html.parser')

type(soup) #bs4.BeautifulSoup

# do find_all on beautifulsoup object
th_all = soup.find_all('th')

# the result is of type bs4.element.ResultSet or similarly list
type(th_all) #bs4.element.ResultSet
type(th_all[0:1]) #list

# now I want to further do find_all
th_all.find_all(text='A') #not work

# can I avoid this …
Run Code Online (Sandbox Code Playgroud)

html python beautifulsoup html-parsing

13
推荐指数
1
解决办法
3万
查看次数

在ESLint中扩展多个推荐配置

故事:

目前,我们正在扩展推荐的ESLint配置:

{
  "extends": "eslint:recommended",
  ...
  "plugins": [
    "angular",
    "jasmine",
    "protractor"
  ],
  "rules": {
    "no-multiple-empty-lines": 2,
    "no-trailing-spaces": 2,
    "jasmine/valid-expect": 2
  }
}
Run Code Online (Sandbox Code Playgroud)

并且还使用angular,jasmineprotractorESLint插件,这也与船自己的推荐配置(默认规则的严格水平和默认规则参数).

问题:

我们如何使用在同一时间所有的推荐配置 - 在一个ESLint和所有使用的插件附带?


尝试以下方法:

{
  "extends": [
    "eslint:recommended",
    "plugin:protractor/recommended",
    "plugin:jasmine/recommended",
    "plugin:angular/recommended"
  ],
  ...
}
Run Code Online (Sandbox Code Playgroud)

但得到以下错误:

无法读取未定义的"推荐"属性

javascript static-code-analysis jasmine angularjs eslint

13
推荐指数
1
解决办法
6662
查看次数