在课堂上,我有:如何从HTML页面文件中提取日期和时间?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
namespace SatelliteImages
{
class ExtractImages
{
static WebClient client;
List<string> imagesUrls = new List<string>();
static string htmltoextract;
static string link;
static string text;
public static List<string> countriescodes = new List<string>();
public static List<string> countriesnames = new List<string>();
private static int lastsatimage = 0;
private static string Next_Sat_File;
private static string temp_sat_dir;
public void Init()
{
ExtractCountires();
}
public static void ExtractCountires()
{
try
{
htmltoextract = "http://sat24.com/en/?ir=true";
client = new WebClient();
client.DownloadFile(htmltoextract, @"c:\temp\sat24.html");
client.Dispose();
string tag1 = "<li><a href=\"/en/";
string tag2 = "</a></li>";
string s = System.IO.File.ReadAllText(@"c:\temp\sat24.html");
s = s.Substring(s.IndexOf(tag1));
s = s.Substring(0, s.LastIndexOf(tag2) + tag2.ToCharArray().Length);
s = s.Replace("\r", "").Replace("\n", "").Replace(" ", "");
string[] parts = s.Split(new string[] { tag1, tag2 }, StringSplitOptions.RemoveEmptyEntries);
string tag3 = "<li><ahref=\"/en/";
for (int i = 0; i < parts.Length; i++)
{
if (i == 17)
{
break;
}
string l = "";
if (parts[i].Contains(tag3))
l = parts[i].Replace(tag3, "");
string z1 = l.Substring(0, l.IndexOf('"'));
countriescodes.Add(z1);
string z2 = parts[i].Substring(parts[i].LastIndexOf('>') + 1);
countriesnames.Add(z2);
}
}
catch (Exception e)
{
}
}
}
}
我发现,在该文件中读取sat24.html文件时的日期和时间在这个部分中的HTML文件:
var arrayImageTimes = [];
arrayImageTimes.push('201612271810');arrayImageTimes.push('201612271825');arrayImageTimes.push('201612271840');arrayImageTimes.push('201612271855');arrayImageTimes.push('201612271910');arrayImageTimes.push('201612271925');arrayImageTimes.push('201612271940');arrayImageTimes.push('201612271955');arrayImageTimes.push('201612272010');arrayImageTimes.push('201612272025');
那么什么我想要做的是提取日期和时间,并将它们添加到两个列表:201612271810因此,第一个列表将是这种格式。
第二个名单是日期和时间,不知道是什么格式,但是:年=2016个月= 12天=27小时=18分钟= 10
什么,我想以后做的是建立一个新的链接对于每个日期和时间新的链接应该是这种格式:如果我们采取例如日期和时间201612271810.然后:http://www.sat24.com/image2.ashx?region=is&time=201612271810&ir=true问题是我如何提取日期和时间,然后使用我的ExtractCountries方法来建立链接。 在ExtractCountries方法中,我得到两个列表中的一个国家代码和一个国家名称。
我需要建立链接的是国家/地区代码和国家/地区的日期和时间。
于是我就可以使用代码的列表,并附有日期时间,例如:
第一个列表会的日期和时间,因为他们是在HTML文件格式:比如第一次约会和时间:
http://www.sat24.com/image2.ashx?region=is&time=201612271810&ir=true
哪里=以色列和201612271810的日期时间该图片链接。 或者例如
http://www.sat24.com/image2.ashx?region=tu&time=201612271810&ir=true
地区TU是土耳其
所以我需要的是得到的来自所有国家的代码和每个区域(countrey)所有日期和时间建立链接列表,以便我可以在以后下载图片。因此,在列表例如URI字符串类型或字符串列表类型
将在第一10个指数法是这样的:
http://www.sat24.com/image2.ashx?region=tu&time=201612271825&ir=true
http://www.sat24.com/image2.ashx?region=tu&time=201612271840&ir=true
http://www.sat24.com/image2.ashx?region=tu&time=201612271855&ir=true
http://www.sat24.com/image2.ashx?region=tu&time=201612271910&ir=true
.
.
.
.
.
.
http://www.sat24.com/image2.ashx?region=is&time=201612271810&ir=true
http://www.sat24.com/image2.ashx?region=is&time=201612271825&ir=true
http://www.sat24.com/image2.ashx?region=is&time=201612271840&ir=true
http://www.sat24.com/image2.ashx?region=is&time=201612271910&ir=true
Ofcourse dpending从sat24页面每个区域/国家提取的日期和时间。
然后当完成创建列表下载图像。例如每个链接:http://www.sat24.com/image2.ashx?region=is&time=201612271910&ir=true应该被下载并保存为图像。
您应该使用HTML敏捷性包。 – SLaks