-1

これはコードです:

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;
using System.Text.RegularExpressions;
using System.IO;

namespace DownloadImages
{
    public partial class Form1 : Form
    {
        string f;

        public Form1()
        {
            InitializeComponent();

            string localFilename = @"d:\localpath\";

                using (WebClient client = new WebClient())
                {
                    client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=1&continent=europa#",localFilename + "test.html");
                }

                f = File.ReadAllText(localFilename + "test.html");
                test();
        }

        private void test()
        {
            List<string> imagesUrls = new List<string>();
            int startIndex = 0;
            int endIndex = 0;
            int position = 0;

            string startTag = "http://www.niederschlagsradar.de/images.aspx";
            string endTag = "cultuur=en-GB&continent=europa";    
            startIndex = f.IndexOf(startTag);

            while (startIndex > 0)
            {

                endIndex = f.IndexOf(endTag,startIndex);
                if (endIndex == -1)
                {
                    break;
                }
                string t = f.Substring(startIndex, endIndex - startIndex + endTag.Length);
                imagesUrls.Add(t);    
                position = endIndex + endTag.Length;    
                startIndex = f.IndexOf(startTag,position);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

最後のリストには 63 個のインデックスが含まれています。たとえば、インデックス 0 の最初のものには次が含まれます。

http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&datum=201309151800&cultuur=en-GB&continent=europa

たとえば、インデックス 5 には以下が含まれます。

http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&datum=201309160600&cultuur=en-GB&continent=europa

最後のインデックスが問題です。他のインデックスと同様に必要な文字列が含まれていますが、この最後のインデックスの残りのファイルコンテンツも含まれています。

これは最後のインデックスの一部です:

http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&cultuur=thumbnail&continent=europa" border="0"/></a></li><li style="margin-top: -12px;text-align: center;"><a href="/?ir=true&co=true&li=false" target="_top" class="white"><div 

ただし、最後のインデックスは次のようにする必要があります。

http://www.niederschlagsradar.de/images.aspx?jaar=-6&type=europa.precip&cultuur=thumbnail&continent=europa

どうすれば解決できますか?

4

2 に答える 2