kittykut
Senior Member
- Feb 9, 2016
- 1,094
- 833
Hello Everyone
I am looking for some help with my very simple keyword bot.
It seems to work perfectly except for one issue:
When It closes the driver and tries to restart using the proxy information I give it it starts without the proxy.
Any help would be wonderful, I think it should be pretty simple
thank you for reading
I am looking for some help with my very simple keyword bot.
It seems to work perfectly except for one issue:
When It closes the driver and tries to restart using the proxy information I give it it starts without the proxy.
Any help would be wonderful, I think it should be pretty simple
Code:
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class idek {
// Keyword and proxy variables
static String keyword;
static String proxy;
public static void main(String[] args) throws InterruptedException, IOException {
// Creates an array of keywords called arr
Path path = FileSystems.getDefault().getPath("src/info", "keywords.txt");
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
String[] arr = lines.toArray(new String[lines.size()]);
// Creates an array of proxies called proxies
Path path1 = FileSystems.getDefault().getPath("src/info", "proxies.txt");
List<String> linez = Files.readAllLines(path1, StandardCharsets.UTF_8);
String[] proxies = linez.toArray(new String[linez.size()]);
// Sets web driver
System.setProperty("webdriver.gecko.driver","C:\\Users\\skr1ptk1tty\\Desktop\\geckodriver.exe");
// loop through all keywords changing proxy each time
for(int i = 0; i<arr.length; i++){
proxy = proxies[i].substring(1);
keyword = arr[i].substring(1);
passTraffixThroughProxyTest(keyword, proxy);
}
}
public static void passTraffixThroughProxyTest(String keyword, String proxy) throws InterruptedException {
DesiredCapabilities capability = new DesiredCapabilities();
addProxyCapabilities(capability, proxy, proxy, proxy);
FirefoxDriver driver = new FirefoxDriver(new DesiredCapabilities(capability));
// Go to MOZ.com and print keyword difficulty
driver.get("https://moz.com/explorer/overview?q="+keyword);
Thread.sleep(5000);
String getDifficulty = driver.findElement(By.xpath("//*[@id=\"main\"]/div[2]/div[1]/section/div/section/section/section[1]/div[2]/span")).getText();
System.out.println("Keyword Difficulty for "+keyword+" is: "+getDifficulty);
//Close Driver
driver.close();
driver.quit();
}
public static DesiredCapabilities addProxyCapabilities(DesiredCapabilities capability, String httpProxy, String sslProxy,
String ftpProxy) {
Proxy proxy = new Proxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setHttpProxy(httpProxy);
proxy.setSslProxy(sslProxy);
proxy.setFtpProxy(ftpProxy);
capability.setCapability(CapabilityType.PROXY, proxy);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
return capability;
}
}
thank you for reading