在我的本地Windows机器上,我如何编写脚本每天下载漫画并通过电子邮件发送给自己?

nop*_*ole 5 php ruby python scheduled-tasks

在我的本地Windows机器上,我如何编写脚本每天下载漫画并通过电子邮件发送给自己?

例如
http://comics.com/peanuts/

更新:我知道如何将图像下载为文件.困难的部分是如何从我的本地Windows机器发送电子邮件.

Gar*_*ers 8

这取决于你想要的精确程度.正如Earwicker在上面提到的,使用wget下载整个网页并不会太具挑战性.

如果你想下载漫画的实际图像文件,你需要在你的武器库中多一点.在Python中 - 因为这是我最了解的 - 我想你需要使用urllib来访问页面,然后使用正则表达式来识别页面的正确部分.因此,您需要知道页面的确切布局和图像的绝对URL.

例如,对于XKCD,以下工作:

#!/usr/bin/env python

import re, urllib

root_url = 'http://xkcd.com/'
img_url  = r'http://imgs.xkcd.com/comics/'

dl_dir   = '/path/to/download/directory/'

# Open the page URL and identify comic image URL
page  = urllib.urlopen(root_url).read()
comic = re.match(r'%s[\w]+?\.(png|jpg)' % img_url, page)

# Generate the filename
fname = re.sub(img_url, '', comic)

# Download the image to the specified download directory
try:
    image = urllib.urlretrieve(comic, '%s%s' % (dl_dir, fname))
except ContentTooShortError:
    print 'Download interrupted.'
else:
    print 'Download successful.'
Run Code Online (Sandbox Code Playgroud)

然后您可以通过电子邮件发送,但感觉很舒服


Ian*_*ell 1

通过电子邮件发送很容易。选择您最喜欢的语言的库并阅读文档。通过您的常规电子邮件帐户发送它,或为其创建一个新的免费 G​​Mail 帐户。

不过,有时附件确实很棘手。如果没有别的事,请尝试一下您最喜欢的任何库,然后针对您遇到的任何问题发布另一个具体问题。