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

发布于 2024-07-22 04:53:22 字数 250 浏览 3 评论 0原文

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

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

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

on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?

such as
http://comics.com/peanuts/

Update: i know how to download the image as a file. the hard part is how to email it from my local Windows machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

玩心态 2024-07-29 04:53:23

这取决于您想要的精确程度。 下载整个网页不会太有挑战性 - 使用 wget,正如 Earwicker 上面提到的。

如果您想要下载漫画的实际图像文件,您的武器库中将需要更多的文件。 在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.'

然后您可以根据需要通过电子邮件发送。

This depends how precise you want to be. Downloading the entire web page wouldn't be too challenging - using wget, as Earwicker mentions above.

If you want the actual image file of the comic downloaded, you would need a bit more in your arsenal. In Python - because that's what I know best - I would imagine you'd need to use urllib to access the page, and then a regular expression to identify the correct part of the page. Therefore you will need to know the exact layout of the page and the absolute URL of the image.

For XKCD, for example, the following works:

#!/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.'

You can then email it however you feel comfortable.

白云悠悠 2024-07-29 04:53:23

快速浏览一下谷歌就会发现两个命令行程序,您应该能够将它们捆绑在一个批处理文件中或使用您选择的脚本语言。

http://www.gnu.org/software/wget/ - 进行下载

http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm - 发送电子邮件

您可以使用控制面板中的 Windows 任务计划程序使其每天运行。

如果您使用 Python,肯定会有方便的库来完成下载/电子邮件部分 - 浏览官方 Python 站点。

A quick look on google reveals two command-line programs that you should be able to lash together in a batch file or using the scripting language of your choice.

http://www.gnu.org/software/wget/ - to do the download

http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm - to send the email

You can use the Windows Task Scheduler in control panel to make it run daily.

If you are using Python there are surely going to be convenient libraries to do the downloading/emailing parts - browse the official Python site.

岛徒 2024-07-29 04:53:23

在 RSS 提要上配置 feedburner,订阅电子邮件警报?

Configure feedburner on the RSS feed, subscribe yourself to the email alerts?

等你爱我 2024-07-29 04:53:23

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

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

Emailing it is easy. Pick a library in your favorite language and read the documentation. Send it through your regular email account, or create a new free GMail account for it.

Sometimes attachments can indeed be tricky, though. If nothing else, give it a good whirl with whatever library you like most, and post another specific question about any problems you encounter.

吐个泡泡 2024-07-29 04:53:23

这也许是您到达目标的最短距离。

这并不简单...您需要弄清楚如何解析图像,而花生示例似乎是一个不可预测的 URI,因此获取图像本身可能比看起来更困难。 最好的办法是读取远程网页的 HTML编写正则表达式来解析图像 URL。 然后邮件函数就可以正常工作了,通过将mail()函数中的标题设置为类似以下内容来发送HTML电子邮件:

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;";
$headers .= " charset=iso-8859-1\r\n";

在邮件中添加图像标签。 这将让您收到一封电子邮件,其中包含一张接一张的所有漫画。 您的电子邮件软件将执行 HTTP 请求来为您下载图像,因此您可以避免直接附加图像。

Here is perhaps the shortest distance to your goal.

It's not simple... you will need to work out how to parse out the image, and the peanuts example seems to be an unpredictable URI, so it might be more difficult than it looks to get the image itself. Your best bet will be to read the HTML of the remote webpage, write a regex to parse out the image url. Then the mail function will work fine, send an HTML email by setting the headers in the mail() function to something like:

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;";
$headers .= " charset=iso-8859-1\r\n";

With the image tags in the mail. This will let you receive emails with all your comic strips placed one after another. Your email software will do the HTTP requests to download the images for you, so you can avoid having to attach the images directly.

阳光下慵懒的猫 2024-07-29 04:53:23

如果您已经知道如何下载文件,那就非常简单了。 下载完成后,创建一个 cronjob,将其通过电子邮件发送给您自己。

使用 phpmailer 之类的东西是发送电子邮件的最简单方法

http://phpmailer.codeworxtech。 com/index.php?pg=examplebmail

It's pretty simple if you already know how to download the file. Once its downloaded create a cronjob that emails it to yourself.

Using something like phpmailer would be the easiest way to email it

http://phpmailer.codeworxtech.com/index.php?pg=examplebmail

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文