如何用程序获得电子邮箱[email protected]中的用户名和域名Python

Python014

如何用程序获得电子邮箱zhangsan@163.com中的用户名和域名Python,第1张

指导邮箱地址就可以指导用户名和域名了,不用使用任何程序。

你的邮箱地址就是这个邮箱用户名。

域名是@后面的内容,这个邮箱就是163.com。

这种方法为从urlparse模块中通过urlparse方法提取url通过hostname属性获取当前url的域名。 此方法是通过urllib模块中splittype方法先从url中获取到proto协议及rest结果,然后通过splithost从rest中获取到host及rest结果,此时host为域名。(rest被分割了两次)如下图: 此方法为从sokcet模块中获取到gethostbyname方法将域名传递进去就能解析出域名的ip。 此方法为通过nslookup获取域名的ip。 以上从域名中提取ip会不准确,需要设置DNS服务器,这样解析域名就准确了。

import rec='sdsdaherf=sadasdada sdad123,21312!!!' pattern=re.compile('herf=(.*)') pattern.findall(c) a=re.findall('herf=(.*)', c) a 结果就是 Out[9]: ['sadasdada sdad123,21312!!!']