无法从网页中读取手机号码 [英] Not Able to read mobile number from a webpage
本文介绍了无法从网页中读取手机号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法阅读手机号码.从网页上,请帮助 这是我的代码:
I am not able to read the mobile no. from a webpage, please help Here is the my code :
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);
}
推荐答案
您可以使用以下代码获取电话号码
You can use the below code to get the phone number
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));
}
这篇关于无法从网页中读取手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文