我无法阅读手机号码。从网页上,请帮忙 这是我的代码:
public void g()
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\cchauhan\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.justdial.com/Ahmedabad/Knife-Fork-Restaurant-Shah-E-Alam-Tollnaka-Opposite-Swaminarayan-College-Shah-Alam/079PXX79-XX79-170524174654-D3J2_BZDET?xid=QWhtZWRhYmFkIEFmZ2hhbmkgUmVzdGF1cmFudHM=");
Thread.sleep(3000);
String mobile = driver.findElement(By.xpath(".//*[@id='comp-contact']/span[2]/a[1]/span[4]")).getText();
System.out.println(mobile);
}
答案 0 :(得分:1)
您可以使用以下代码获取电话号码
driver.navigate().to("https://www.justdial.com/Ahmedabad/Knife-Fork-Restaurant-Shah-E-Alam-Tollnaka-Opposite-Swaminarayan-College-Shah-Alam/079PXX79-XX79-170524174654-D3J2_BZDET?xid=QWhtZWRhYmFkIEFmZ2hhbmkgUmVzdGF1cmFudHM=");
Thread.sleep(3000);
String mobile = driver.findElement(By.xpath("//div[contains(@class,'businfo seoshow')]/span/p[3]")).getText();
Pattern pattern = Pattern.compile("\\d{10},\\d{10}");
Matcher matcher = pattern.matcher(mobile);
if (matcher.find()) {
System.out.println(matcher.group(0));
}