Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python3库用于识别电话号码、姓名、电子邮件和地址_Python_Python 3.x_Selenium_Nltk - Fatal编程技术网

python3库用于识别电话号码、姓名、电子邮件和地址

python3库用于识别电话号码、姓名、电子邮件和地址,python,python-3.x,selenium,nltk,Python,Python 3.x,Selenium,Nltk,假设我已成功获取此文本,然后将其命名为textToModify: textToModify = " abcde abcde Title: Director, lorem company Phone: 123.647.4555 Mobile: 123.123.1234 E-mail: try1@umich.edu Assistant: my name

假设我已成功获取此文本,然后将其命名为textToModify:

textToModify = "
abcde abcde
Title: Director, lorem company
                    Phone: 123.647.4555                 
Mobile: 123.123.1234                    E-mail: try1@umich.edu                  Assistant: my name                  Assistant Phone: 667.889.9910

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Linkedin: www.linkedin.com/in/lorem-ipsum/
Twitter: www.twitter.com/ipsum
"
现在我想从本文中提取标题、姓名、电话号码、linkedin、twitter和其他重要信息。有这样的图书馆吗?或者你有什么想法?假设此文本的格式是随机的,但单词title将始终位于标题本身的旁边,单词phone将始终位于电话的旁边,等等

我最初的想法是:

nltk
库不起作用,因为它基本上是用标识符分配单词,问题是,此文本不是按单词分隔的,而是按字符分隔的,例如,如果访问textToModify[20],它将只返回一个字符。

我的另一个想法是,如果我访问链接,然后截图,然后在python中使用(如果存在)图片到文本库,然后从那里开始呢


谢谢大家!

如果变量中有它,可以使用
python
re
模块使用regex进行匹配

地址和电话号码

向您展示了检测电子邮件的逐步步骤

对于名称和地址,除非它们前面有
名称:
地址:
,或者您可以应用一些逻辑来查找它,否则您可能会遇到比您以前想象的更困难的时间。给出了一个尝试匹配地址的示例


希望这有帮助。我想写一个完整的答案,但是SO和其他网站上的
RegEx
资源相当丰富

像这样的程序可以满足您的需求:

finds = {}
texttoModify = texttoModify.split()
for element in enumerate(texttoModify):
    if element[1] == 'Title:':
        finds['title'] = texttoModify[element[0]+1]

但是您需要为每个要获取的元素创建if's,并为后面的两个元素(例如带有两个单词的名称)创建if's。

这听起来像是一个错误。编辑您的问题并询问实际问题,而不是寻求帮助解决问题。你想干什么?你比我强:)RegEx是个很好的建议谢谢@NarendraR