【问题标题】:How to fetch list of hyperlink on webpage based on only the image color corresponding to these hyperlinks?如何仅根据这些超链接对应的图像颜色获取网页上的超链接列表?
【发布时间】:2018-04-22 21:22:49
【问题描述】:

我需要使用 Selenium Webdriver 获取带有红色/绿色项目符号的网页上的超链接列表。可能吗?这些超链接是根据用户提供的 IP 动态生成的。 例如,当用户访问 http://www.dnsbl.info/ 并输入任何特定的 IP 地址时,我需要获取一个绿色超链接列表和另一个包含红色超链接的列表。这个场景可以使用 webdriver 自动化吗?

下面列出的是我现在的脚本:

public class SelectCategory extends Config {

    public static WebDriver driver;

    @Test(enabled = true)

    public void Blacklist1() throws IOException {

        Properties p = new Properties(GetDataFromFile());

        System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        driver = new FirefoxDriver();
        driver.get(p.getProperty("BLURL"));

        WebElement D1 = driver.findElement(By.xpath(".//*[@id='quickcheck']/input[1]"));
        D1.clear();
        D1.sendKeys(p.getProperty("IP1"));

        WebElement D2 = driver.findElement(By.xpath(".//*[@id='quickcheck']/input[2]"));
        D2.click();

    }

    public Properties GetDataFromFile() throws IOException {
        File F = new File("*Path of properties file");
        FileInputStream fis = new FileInputStream(F);
        Properties prop = new Properties();
        prop.load(fis);
        return prop;
    }
}

【问题讨论】:

  • 你的意思是这些超链接有不同的颜色?你能展示一下它们在网络或屏幕截图上的具体外观吗?

标签: css image selenium-webdriver hyperlink background-color


【解决方案1】:

解决这个问题的一种方法,在我看来效率不高,是保存每个 IP 的 img src 链接(通过抓取它们),然后逐个点击每个 img src 链接。

每次点击后,您都需要知道您当前的网址是什么(这就是您现在 IP 的颜色。 这是一个例子,这是其中一个IP彩球的元素:

<img height="15" width="15" src="http://www1.dnsbl.info/test-a.php?bl=bl.emailbasura.org&ip=208.87.233.201&cb=1123477419&token=0f46ad74b3eb0606dc4644be7218d0d5" alt="">

你基本上需要解析变量src里面的链接。

绿色图像的网址如下:http://www.dnsbl.info/images/ball_green_15x15.gif
除此以外的任何 url 都不会被视为绿色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2011-04-02
    • 2017-09-15
    • 2013-01-02
    • 2015-02-28
    • 1970-01-01
    相关资源
    最近更新 更多