1

有人可以解释我如何解决这个问题吗?在我尝试使用 IP 旋转运行此代码后,即使在静态 IP 上它也会停止工作。下面的方法打开 cosdna.com 并尝试搜索产品的 Ingridient。在我尝试抓取大约 20 种产品后,我得到了 IP 禁令,所以我尝试轮换我的 IP 来解决这个问题。现在它在有和没有 IP 轮换的情况下都不起作用。

@SuppressWarnings("deprecation")
public static String findInCosDNA(String name) throws SessionNotCreatedException {
    StringBuilder sklad = new StringBuilder();
    sklad.append("Skład/");
    System.setProperty("webdriver.gecko.driver",
            "C:\\...\\geckodriver.exe");
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    capabilities.setCapability(CapabilityType.PROXY, getRandomProxy());
    WebDriver driver = new FirefoxDriver(capabilities);
    try {
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.get(COSDNA);
        WebElement textInput = driver.findElement(By.className("input-gen"));
    .
    .
    .
    } catch (NoSuchElementException e) {
        sklad.setLength(0);
    } catch (TimeoutException e) {
        sklad.setLength(0);
    } catch (WebDriverException e) {
        sklad.setLength(0);
    }
    driver.close();
    return sklad.toString();
}

//proxyList is a list of String in "IP:PORT" format
public static Proxy getRandomProxy() {
    String IP = proxyList.get(getRandomNumberInRange(0, Proxy.size() - 1));
    Proxy prx = new Proxy();
    prx.setHttpProxy(IP).setFtpProxy(IP).setSslProxy(IP);
    return prx;
}

没有代理的错误:

lip 27, 2018 12:18:08 AM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using 'new FirefoxOptions()' is preferred to 'DesiredCapabilities.firefox()'
1532643488955   geckodriver INFO    geckodriver 0.21.0
1532643488963   geckodriver INFO    Listening on 127.0.0.1:27760
1532643489446   mozrunner::runner   INFO    Running command: "C:\\Program   Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\...\\AppData\\Local\\Temp\\rust_mozprofile.Rci2IkveaCHL"
Unable to read VR Path Registry from C:\...\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\openvrpaths.vrpath
Unable to read VR Path Registry from C:\....\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\openvrpaths.vrpath
1532643491280   Marionette  INFO    Listening on port 58941
1532643491606   Marionette  WARN    TLS certificate errors will be ignored for this session
lip 27, 2018 12:18:11 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[Child 21140, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 21140, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 11772, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 11772, Chrome_ChildThread] WARNING: pipe error: *** UTM:SVC TimerManager:registerTimer called after profile-before-change notification.     Ignoring timer registration for id: telemetry_modules_ping
[GPU 9452, Chrome_ChildThread
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot    send/recv'

代理错误:

lip 27, 2018 12:48:03 AM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1532645283430   geckodriver INFO    geckodriver 0.21.0
1532645283439   geckodriver INFO    Listening on 127.0.0.1:27001
1532645283919   mozrunner::runner   INFO    Running command: "C:\\Program         Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\...\\AppData\\Local\\Temp\\rust_mozprofile.pbDkAIWznMhW"
Unable to read VR Path Registry from C:\...\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\...\AppData\Local\openvr\openvrpaths.vrpath
1532645285883   Marionette  INFO    Listening on port 59352
Unable to read VR Path Registry from C:\U...\AppData\Local\openvr\openvrpaths.vrpath
1532645286083   Marionette  WARN    TLS certificate errors will be ignored for this session
1532645286091   Marionette  INFO    Proxy settings initialised: {"proxyType":"manual","ftpProxy":"77.104.208.138:3128","httpProxy":"77.104.208.138:3128","sslProxy":"77.104.208.138:3128"}
lip 27, 2018 12:48:06 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[Child 14744, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 14744, Chrome_ChildThread] WARNING: pipe error: 109: file[Child 11348, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 11348, Chrome_ChildThread] W*** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping
[GPU 21212, Chrome_ChildT
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
4

0 回答 0