Can';在java中使用SeleniumWeb驱动程序无法从网页上的表列获取数据
我想使用java中的selenium web驱动程序从网页上的表列中获取一些连续数据。Can';在java中使用SeleniumWeb驱动程序无法从网页上的表列获取数据,java,selenium,Java,Selenium,我想使用java中的selenium web驱动程序从网页上的表列中获取一些连续数据。 我得到以下错误: org.openqa.selenium.WebDriverException:无法绑定到锁定端口 7054在45000毫秒内 系统信息:os.name:'Windows 8',os.arch:'amd64',os.version:'6.2',java.version:'1.7.0_75' 驱动程序信息:Driver.version:FirefoxDriver 我尝试过更新selenium和f
我得到以下错误: org.openqa.selenium.WebDriverException:无法绑定到锁定端口 7054在45000毫秒内 系统信息:os.name:'Windows 8',os.arch:'amd64',os.version:'6.2',java.version:'1.7.0_75' 驱动程序信息:Driver.version:FirefoxDriver 我尝试过更新selenium和firefox
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
public class webcrawler {
public static String substringBetween(String str, String open, String close) {
if (str == null || open == null || close == null) {
return null;
}
int start = str.indexOf(open);
if (start != -1) {
int end = str.indexOf(close, start + open.length());
if (end != -1) {
return str.substring(start + open.length(), end);
}
}
return null;
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
try {
System.getProperties().put("http.proxyHost", "192.168.10.9");
System.getProperties().put("http.proxyPort", "8080");
String volume = substringBetween("Ticket 3098,OrderID 9712,TRD0890084 Buy 1 Contract(s) of CRUDE10-JY15 @ 59.57","Buy","Contract(s)");
System.out.println("----->"+volume+"<-----");
//System.setProperty("webdriver.chrome.driver","C:\\Users\\Aami\\Downloads\\chromedriver.exe");
//ChromeOptions options = new ChromeOptions();
//options.addArguments("--test-type");
WebDriver driver=new FirefoxDriver();
//WebDriver driver = new ChromeDriver();
driver.get("http://only-testing-blog.blogspot.in/");
Thread.sleep(5000);
//Get number of rows In table.
int Row_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr")).size();
System.out.println("Number Of Rows = "+Row_count);
//Get number of columns In table.
int Col_count = driver.findElements(By.xpath("//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr[1]/td")).size();
System.out.println("Number Of Columns = "+Col_count);
//divided xpath In three parts to pass Row_count and Col_count values.
String first_part = "//*[@id='post-body-6522850981930750493']/div[1]/table/tbody/tr[";
String second_part = "]/td[";
String third_part = "]";
//Used for loop for number of rows.
for (int i=1; i<=Row_count; i++){
//Used for loop for number of columns.
for(int j=1; j<=Col_count; j++){
//Prepared final xpath of specific cell as per values of i and j.
String final_xpath = first_part+i+second_part+j+third_part;
//Will retrieve value from located cell and print It.
String Table_data = driver.findElement(By.xpath(final_xpath)).getText();
System.out.print(Table_data +" ");
driver.quit();
}
System.out.println("");
System.out.println("");
}
} catch (Exception e) {
System.out.println(e);
}
}
}
导入java.io.File;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.chrome.ChromeOptions;
导入org.openqa.selenium.firefox.FirefoxDriver;
公共类网络爬虫器{
公共静态字符串substringBetween(字符串str、字符串open、字符串close){
如果(str==null | | open==null | | close==null){
返回null;
}
int start=str.indexOf(打开);
如果(开始!=-1){
int end=str.indexOf(close,start+open.length());
如果(结束!=-1){
返回str.substring(start+open.length(),end);
}
}
返回null;
}
@抑制警告(“未选中”)
公共静态void main(字符串[]args){
试一试{
System.getProperties().put(“http.proxyHost”、“192.168.10.9”);
System.getProperties().put(“http.proxyPort”、“8080”);
字符串体积=子字符串之间(“票据3098,订单ID 9712,TRD0890084 CRUDE10-JY15@59.57的购买1合同”,“购买”,“合同”);
System.out.println(“--->”+volume+”你有后台运行的驱动程序的僵尸进程吗?不,我不知道。当你在你的计算机上启动服务时,它绑定到一个端口(由网络适配器公开)由1到65535之间的数字标识。您遇到的异常表明将驱动程序的服务绑定到给定端口失败,这可能意味着另一个服务已经绑定到您计算机上的该端口。请检查您的服务,并关闭该端口上的服务。哦,我知道了,现在该怎么办?简单est方法?重新启动计算机并重试。警告:如果端口7054上的进程是在系统启动时启动的,则此方法无效。