【发布时间】:2020-03-01 09:05:02
【问题描述】:
我只想抓取以下格式的手机:
+1 NXX-NXX-XXXX
N=digits 2–9, X=digits 0–9
+1 is the country code that includes the US, there are 17 other countries, e.g., Canada, Caribbean Islands.
假设我们需要找到以 986 和 965 等开头的每个数字(我们有一组这样的数字)作为第一个 NXX。
这是我获取电子邮件的代码:
email = soup(text=re.compile(r'[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*'))
_emailtokens = str(email).replace("\\t", "").replace("\\n", "").split(' ')
if len(_emailtokens):
print([match.group(0) for token in _emailtokens for match in [re.search(r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", str(token.strip()))] if match])
但我需要更改它才能获得手机。
【问题讨论】:
-
您尝试过更改正则表达式吗?
-
亲爱的@Phix,我不知道该怎么做。
-
您尝试在什么文本中查找数字?也许有更好的方法来获得它。
-
亲爱的@furas,我的目的是从网页及其内容中查找数字。
标签: python regex python-3.x web-scraping beautifulsoup