[英]Metaprogramming Python Script for e-mail Capture
How can I modify the code below to capture all e-mails instead of images: 如何修改下面的代码以捕获所有电子邮件而不是图像:
import urllib2
import re
from os.path import basename
from urlparse import urlsplit
url = "URL WITH IMAGES"
urlContent = urllib2.urlopen(url).read()
# HTML image tag: <img src="url" alt="some_text"/>
imgUrls = re.findall('img .*?src="(.*?)"', urlContent)
# download all images
for imgUrl in imgUrls:
try:
imgData = urllib2.urlopen(imgUrl).read()
fileName = basename(urlsplit(imgUrl)[2])
output = open(fileName,'wb')
output.write(imgData)
output.close()
except:
pass
Need to get a directory from an array of websites. 需要从一系列网站获取目录。 I'm using C++ to create code for Unix by calling the .py file multiple times and then appending it to an existing file each time.
我正在使用C ++通过多次调用.py文件然后每次将其附加到现有文件中来为Unix创建代码。
Parsing/validating email address requires a strong regex. 解析/验证电子邮件地址需要强大的正则表达式。 You can look for those on google.
您可以在Google上查找这些内容。 I am showing you a simple email address parsing regex.
我正在向您展示一个简单的电子邮件地址解析正则表达式。
emails = re.findall('([a-zA-Z0-9\.]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3})', urlContent)
This is just a rudimentary example. 这只是一个简单的例子。 You need to use a powerful one.
您需要使用功能强大的软件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.