I am using jsoup to connect to url and load document after that i use regex to check document contain it or not.But it fails in some cases. following code fetch all phone number from some urls but fails in others such as http://www.wellclean.com/ while i checked that document contain phone number while printing doc.
String regex_num = "^\\+?[0-9. ()-]{10,25}$";
Pattern pattern = Pattern.compile(regex_num);
Document doc = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0")
.maxBodySize(0)
.timeout(600000)
.get();
Elements Phone_Num=doc.getElementsMatchingOwnText(pattern);// match regex in doc
if(!Phone_Num.isEmpty()) // if phone number exist
{
System.out.println("Phone number found!");
for(Element e : Phone_Num)
{
PNUM=PNUM+e.text().toString()+" & "; // store all phone number seperated by &
}
}
when i print doc it contains phone number in following format
<div class="contact_address">
<div class="contact_column_1">
2261 N. Clybourn Ave.
<br> Chicago, IL 60614
<br> Ph: (773) 348.2226
<br>
<a href="http://maps.google.com/maps?q=2261+N.+Clybourn+Ave.Chicago,+IL+60614&hl=en&sll=41.923214,-87.666462&sspn=0.014417,0.029268&gl=us&hnear=2261+N+Clybourn+Ave,+Chicago,+Cook,+Illinois+60614&t=m&z=17" target="_new"><img src="/wp-content/themes/artgallery_3.0/images/map.png" alt="map"></a>
<br> Hours:
<br> M-S 7:30am – 7:00pm
<br> Sun 9:00am – 5:00pm
</div>
<div class="contact_column_2">
<br>
</div>