[英]how to Parse emails from mailto urls in Python
我正在嘗試解析網頁中的電子郵件。 我的代碼:
import urllib2,cookielib
import re
site= "http://www.traidnt.net/vb/traidnt207743"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
req = urllib2.Request(site, headers=hdr)
page = urllib2.urlopen(req)
content = page.read()
links = re.findall('mailto:.+?@.+.', content)
for link in links:
print link[7:-1]
結果如下:
email1@
email2@
email3@
...
但是我需要獲取所有具有完整表格的電子郵件。 請我怎么做才能獲得所有電子郵件的完整表格。
謝謝!
我只是將以下代碼添加到您的代碼中,所以效果很好:
regexp = re.compile(("mailto:([a-z0-9!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9]+\.[a-zA-Z0-9-.]+)"))
links = re.findall(regexp, content)
print links
輸出:
['njm-kwt@hotmail.com', 'fnan-ksa@hotmail.com', 'k-w-t7@hotmail.com', 'coool-uae@hotmail.com', 'qsd@hotmail.de', 'o1ooo@hotmail.de', 'm-p-3@hotmail.de', 'ya7oo@hotmail.de', 'g5x@hotmail.de', 'f7t@hotmail.de', 'm2y@hotmail.de', 's2udi@hotmail.de', 'q2tar@hotmail.de', 'kuw2it@hotmail.de', 's2udi@hotmail.fr', 'qxx@hotmail.de', 'y-e-s@hotmail.de', 'y-a@hotmail.de', 'qqj@hotmail.de', 'qjj@hotmail.de', 'admin_vb@hotmail.de', 'eng-vb@hotmail.com', 'a3lantk@hotmail.com', 'a3lnkm@hotmail.com', 't7t@hotmail.de', 'mohamed_fathy41@hotmail.com', 'ox-9@hotmail.com', 'ox-9@hotmail.com']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.