小编Jac*_*ack的帖子

在Selenium Python中禁用图像

因为Webdriver在进入下一行之前等待整个页面加载,我认为禁用图像,css和javascript会加快速度.

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

def disableImages(self):
    ## get the Firefox profile object
    firefoxProfile = FirefoxProfile()
    ## Disable CSS
    firefoxProfile.set_preference('permissions.default.stylesheet', 2)
    ## Disable images
    firefoxProfile.set_preference('permissions.default.image', 2)
    ## Disable Flash
    firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                      'false')
    ## Set the modified profile while creating the browser object 
    self.browserHandle = webdriver.Firefox(firefoxProfile)
Run Code Online (Sandbox Code Playgroud)

我从stackoverflow获取代码不希望加载图像和使用Python在Selenium WebDriver测试中在Firefox上渲染CSS

但是当我补充说

driver = webdriver.Firefox()
driver.get("http://www.stackoverflow.com/")
Run Code Online (Sandbox Code Playgroud)

到最后,它仍然加载图像:/

javascript css python selenium selenium-webdriver

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

Selenium webdriver与python-如果加载太长时间如何重新加载页面?

driver = webdriver.Firefox()               #opens firefox
driver.get("https://www.google.com/")      #loads google
Run Code Online (Sandbox Code Playgroud)

如果加载谷歌需要太长时间,如何让它关闭浏览器并从头开始代码?

python firefox selenium timeout webdriver

4
推荐指数
1
解决办法
3552
查看次数

使用正则表达式检查字符串是否至少有两个数字

在深入研究堆栈溢出后,我发现了一些代码来检查字符串是否为字母数字且超过 8 个字符。它工作得很好。现在,如果它包含至少 2 个数字,我该如何让它返回 true?我想我必须在\d{2}某处添加。

String pattern = "^[a-zA-Z0-9]*$";

if (s.matches(pattern) && s.length() >= 8){
    return true;
}
return false;
Run Code Online (Sandbox Code Playgroud)

java regex

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

使用循环计算e

我试图迭代地计算e,但是我的代码给了我2.知道什么可能是错的?因为我完全卡住了.

public class iteratee {

    public static void main(String[] args) {

        long limit = 0;

        for (int i = 0; i < 11; i++) {

            limit = limit + 1/factorial(i);

        }

        System.out.println(limit);

    }

    static int factorial(int n) {

        int factorial = 1;

        for (int j = 1; j <= n; j++) {
            factorial = factorial * j;
        }

        return factorial; 

    }

}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
119
查看次数

检查字符串是否是回文

for (int i = 0; i <= (line.length()/2); i++) {  \\loops from the first character until the character in the middle
    if (line.charAt(i) != line.charAt(line.length() - i)) {  \\checks if 1st character of line is not equal to the last character, and so on..
        System.out.println("Entered string is not a palindrome.");
        return; \\ends program, no need to check anything else
    }
}
System.out.println("Entered string is a palindrome.");
Run Code Online (Sandbox Code Playgroud)

我不断得到索引超出范围错误

java palindrome

-5
推荐指数
1
解决办法
114
查看次数