Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using unfreez_wrapper;
- namespace Extract
- {
- public partial class Form1 : Form
- {
- string[] statements;
- List<string> urls = new List<string>();
- WebClient client;
- public Form1()
- {
- InitializeComponent();
- label3.Text = "";
- ExtractLinks();
- }
- private void ExtractLinks()
- {
- using (WebClient client = new WebClient())
- {
- client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36");
- client.DownloadFile("https://de.sat24.com/de/eu/infraPolair/", @"D:\localfile.html");
- var file = File.ReadAllText(@"D:\localfile.html");
- int idx = file.IndexOf("arrayImageTimes.push");
- int idx1 = file.IndexOf("</script>", idx);
- string results = file.Substring(idx, idx1 - idx);
- statements = results.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < statements.Length; i++)
- {
- if (i == 10)
- {
- break;
- }
- string number = statements[i].Split('\'')[1];
- urls.Add("https://de.sat24.com/image?type=infraPolair®ion=eu×tamp=" + number);
- }
- }
- }
- private async Task DownloadAsync()
- {
- using (var client = new WebClient())
- {
- client.DownloadFileCompleted += (s, e) => label1.Text = "Download file completed.";
- client.DownloadProgressChanged += (s, e) => progressBar1.Value = e.ProgressPercentage;
- client.DownloadProgressChanged += (s, e) => label2.Text = FormatBytes(e.BytesReceived);
- client.DownloadProgressChanged += (s, e) =>
- {
- label3.Text = "%" + e.ProgressPercentage.ToString();
- label3.Left = Math.Min(
- (int)(progressBar1.Left + e.ProgressPercentage / 100f * progressBar1.Width),
- progressBar1.Width - label3.Width
- );
- };
- for (int i = 0; i < urls.Count; i++)
- {
- await client.DownloadFileTaskAsync(new Uri(urls[i]), @"d:\satImages\img" + i + ".gif");
- }
- }
- }
- void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private async void Button1_Click(object sender, EventArgs e)
- {
- await DownloadAsync();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- }
- private string FormatBytes(long bytes)
- {
- string[] Suffix = { "B", "KB", "MB", "GB", "TB" };
- int i;
- double dblSByte = bytes;
- for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024)
- {
- dblSByte = bytes / 1024.0;
- }
- return String.Format("{0:0.00} {1}", dblSByte, Suffix[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement