MCPcopy
hub / github.com/DedSecInside/TorBot / parse_phone_numbers

Function parse_phone_numbers

torbot/modules/linktree.py:177–201  ·  view source on GitHub ↗

Finds all anchor tags and parses the href attribute. example attribute: `tel:+45651112331` or possiby the href attribute itself.

(soup: BeautifulSoup)

Source from the content-addressed store, hash-verified

175
176
177def parse_phone_numbers(soup: BeautifulSoup) -> list[str]:
178 """
179 Finds all anchor tags and parses the href attribute.
180 example attribute: `tel:+45651112331` or possiby the href attribute itself.
181 """
182 tags = soup.find_all('a')
183 numbers = set()
184 for tag in tags:
185 if tag.has_attr('href') and 'tel:' in tag['href']:
186 number = tag['href'].split('tel:', 1)[1]
187 try:
188 if phonenumbers.is_valid_number(number):
189 numbers.add(number)
190 except Exception as e:
191 logging.debug(e)
192 pass
193
194 try:
195 if phonenumbers.is_valid_number(tag['href']):
196 numbers.add(tag['href'])
197 except Exception as e:
198 logging.debug(e)
199 pass
200
201 return list(numbers)

Callers 1

_append_nodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected