【发布时间】:2013-09-14 21:43:51
【问题描述】:
这是网站:
http://www.sat24.com/foreloop.aspx?type=1&continent=europa# 那里的图像循环移动。
这是一张图片的 url 示例:
http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&datum=201309171200&cultuur=en-GB&continent=europa 中间有时间日期:201309171200 我需要以某种方式自动解析每个 url 的时间和日期。
例如构建一些字符串:
"www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&datum=" + parsedDateAndTime + &cultuur=en-GB&continent=europa 到目前为止我尝试的是这样的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
namespace DownloadImages
{
public partial class Form1 : Form
{
int counter;
public Form1()
{
InitializeComponent();
counter = 0;
string localFilename = @"d:\localpath\";
while (true)
{
using (WebClient client = new WebClient())
{
client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=1&continent=europa#", localFilename + counter.ToString("D6") + ".jpg");
counter++;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
但我还没有解析任何 url,我只是使用主循环 url,我看到它每次都在下载 46kb 文件,但我无法打开它们,我得到一个错误,画图无法打开它......等等
我这样做的方式是错误的。
如何从循环中下载站点中的每个图像?
如何从每张图片中解析日期和时间,这样它就不会一直下载同一张图片?我需要以某种方式获取每个图像网址的日期和时间,并将其用作标志或其他东西,这样它就不会下载相同的文件。
编辑**
例如,每个图像的每个 url 的日期和时间都在变化:
日期和时间会根据循环变化,就像在网站中一样,如果您右键单击图像并制作:复制图像URL,您可以看到时间和日期是每张图像的变化。
【问题讨论】:
-
您无法打开图像,因为在您的代码中您正在下载一个 gif 文件,您的代码提供了 *.jpg 扩展名
-
除非您改进它,否则两次发布相同的问题对您没有多大帮助。 stackoverflow.com/questions/18805142/…
-
放更多信息。就像日期时间是随机使用或固定的。并且您此时正在更改扩展名。我以为你必须下载原始图像,它会正常打开
-
日期和时间在循环中每个 url 都是固定的。
-
更改了扩展gif的行:localFilename + counter.ToString("D6") + ".gif" 仍然无法打开文件同样的错误。