Need a tool to detect and scrape phone numbers in various environments

Dred Shep

Newbie
Joined
Oct 22, 2018
Messages
9
Reaction score
1
Does anyone here know of a tool that allows me to detect various formats of phone numbers? I need to analyze long texts and find if these long texts have phone numbers.

The problem is that the texts also contain other numbers (amounts and counts, various IDs). I can take some margin of error, and it shouldn't matter whether they have the country code or if the country code is preceded by 00 or +.

They can also have parentheses, spaces, hyphens. I've found a few that take very specific formats. I could make a compilation of those.

I found these regexes (stackoverflow (dot) com/questions/2113908/what-regular-expression-will-match-valid-international-phone-numbers), but they're all too specific. The regexes are each for very specific environments. Some can take anything from 3 to 14 numbers, others need a + and don't take into account spaces and parentheses, etc.

I also found a url scraper (scrapebox (dot) com/phone-number-scraper). But it is only for urls and is really not adaptive or API-like.

I come here because you'll probably deal with these scenarios more often. Does anyone know of solutions to this problem?
 
Thread moved.
 
I would write a little python script with all regexes that fit your needs (instead of defining 1 regex that matches perfectly your needs, that would be to hard.)
that should be quite easy task
 
This is the Python script for scraping phones and emails:

Code:
import urllib,re
f = urllib.urlopen("https://gist.github.com/dhruvbaldawa/1476680/bc58a7bafbf9c4da9a9c03273c55045c4cb4bacd")
s = f.read()
phones = re.findall(r"\+\d{2}\s?0?\d{10}",s)
emails = re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",s)
print phones

I used Python 2.7
The output will be:
$ python phone.py
['+02 2323123789', '+01 2334325323', '+00 2323123323', '+02 2323123789', '+01 2334325323', '+00 2323123323']
 
You have narrowed it down pretty well. I am not sure if a library already exists with patterns of phone numbers (it should, right? ). Regular expressions is the solution.
 
Back
Top