Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Dynamic proxy failure, ask how to achieve #2051

Closed
lxtqq opened this issue Nov 8, 2024 · 2 comments
Closed

[🐛 Bug]: Dynamic proxy failure, ask how to achieve #2051

lxtqq opened this issue Nov 8, 2024 · 2 comments
Labels
I-question Further information is requested

Comments

@lxtqq
Copy link

lxtqq commented Nov 8, 2024

What happened?

In the test, the IP is not a proxy IP,
curl-x http://xxxx:[email protected]:8091 http://httpbin.org/ip indicates that the IP address is inconsistent each time
Then the agent is OK, that is selenium configuration error

What browsers and operating systems are you seeing the problem on?

disposition

My Google is       113.0.5672.93
Google Drive is   113.0.5672.24

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-devtools-v113</artifactId>
            <version>4.11.0</version>
        </dependency>

CODE

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

public class WebDriverManager {

    private static final Logger log = LoggerFactory.getLogger(WebDriverManager.class);
    private static final String PROXIES_CONFIG = "dtqybf.xiongmaodaili.com:8091";

    public static void main(String[] args) {
        WebDriver driver = getWebDriver();
        driver.get("http://httpbin.org/ip");
        WebElement body = driver.findElement(By.tagName("body"));
        driver.quit();
    }

    public static WebDriver getWebDriver() {
        System.setProperty("webdriver.chrome.driver", "C:/Users/aa/AppData/Local/Google/Chrome/Application/chromedriver.exe");

        // 配置ChromeOptions
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("--disable-gpu");
        options.addArguments("--remote-allow-origins=*");
        options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.92 Safari/537.3");
        options.addArguments("--disable-blink-features=AutomationControlled");
        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
        if (PROXIES_CONFIG != null && !PROXIES_CONFIG.isEmpty()) {
            String selectedProxy = "0IWHbXLW:fiUPnLxm@" + PROXIES_CONFIG;
            Proxy seleniumProxy = new Proxy();
            seleniumProxy.setHttpProxy(selectedProxy);
            seleniumProxy.setFtpProxy(selectedProxy);
            seleniumProxy.setSslProxy(selectedProxy);
            options.setCapability(CapabilityType.PROXY, seleniumProxy);
            options.setAcceptInsecureCerts(true);
        }
        ChromeDriver driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        return driver;
    }
}
@lxtqq lxtqq added bug Something isn't working needs-triaging labels Nov 8, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

@lxtqq, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol diemol added I-question Further information is requested and removed bug Something isn't working needs-triaging labels Nov 10, 2024
Copy link
Contributor

💬 Please ask questions at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants