首页 > 解决方案 > hideproxy.me 上的自动化问题

问题描述

为什么我在“ https://us.hideproxy.me/ ”上搜索时无法在页面中获取文本?我的代码在 google.com 上成功运行。好的,没问题,但是在这个站点上运行相同的代码,我只能得到空文本或空文本。代码使用 selenium 3.11 并使用 FirefoxDriver 进行开发。在https://us.hideproxy.me输出:

>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>

google.com 输出上的相同代码:

>>>>>Спецтехника Caterpillar: дорожная, строительная техника CAT ...
>>>>>Customer Applications and Portals - Lifecycle Support | Solar Turbines
>>>>>Teknoxgroup: Home
>>>>>Caterpillar | Education
>>>>>Cat | Rental Power - Commercial and Industrial Generator Rental ...
>>>>>Caterpillar | Dealer Technician
>>>>>About Us | Solar Turbines
>>>>>Cat | Marine Product Support | Caterpillar
>>>>>Energy Power Systems | Caterpillar Generators & Cat Engines Australia
>>>>>Caterpillar | Financial Information www.cat.com/proxy

编码:

driver.get("https://us.hideproxy.me/");
driver.findElement(By.className("url-input")).sendKeys("https://www.google.com/search?q=site:" + "cat.com");
driver.findElement(By.className("url-button")).click();
String resultText = "";
List<WebElement> elements = driver.findElements(By.xpath("//div[@class='g']"));
for (WebElement element : elements) {
    resultText = resultText + ">>>>>" + element.getText() + "\n";
}

标签: seleniumautomation

解决方案


你能试试吗(它适用于 python。你可以为其他语言找到相同的 do 行。) time.sleep(-some seconds-) 行?也许在页面加载之前,您的代码会尝试自行运行。


推荐阅读