在c#中只获取一个url

时间:2015-03-26 10:21:46

标签: c# .net watin

我正在使用WatiN框架从C#中的网站收集网址。在我的程序中,它只获取一个URL。我不知道是什么问题。任何帮助将不胜感激。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WatiN.Core;
using WatiN.Core.Native.InternetExplorer;

namespace magicbricks
{
    class scroll
    {
        [STAThread]
        static void Main(string[] args)
        {
            Browser browserInstance;
            browserInstance = new IE(@"http://www.99acres.com/property-in-chennai-  ffid?search_type=QS&search_location=CP32&lstAcn=CP_R&lstAcnId=32&src=CLUSTER&isvoicesearch=N&keyword_suggest=chennai%20%28all%29%3B&fullSelectedSuggestions=chennai%20%28all%29&strEntityMap=W3sidHlwZSI6ImNpdHkifSx7IjEiOlsiY2hlbm5haSAoYWxsKSIsIkNJVFlfMzIsIFBSRUZFUkVOQ0VfUywgUkVTQ09NX1IiXX1d&texttypedtillsuggestion=chennai&refine_results=Y&Refine_Localities=Refine%20Localities&action=%2Fdo%2Fquicksearch%2Fsearch&suggestion=CITY_32%2C%20PREFERENCE_S%2C%20RESCOM_R");

            foreach (var links in browserInstance.Links.Filter(Find.ByClass("b")))
            {
                Console.WriteLine(links.Url);
                String filePath = "C:/Users/User/Desktop/New folder";
                String fileName = "newop4.csv";

                using (StreamWriter sr = new StreamWriter(Path.Combine(filePath, fileName), true))
                    {
                        sr.WriteLine(links.Url);
                    }
                    Console.ReadLine();
                }
            }
        }
    }

上面的代码只在控制台中打印一个网址。

1 个答案:

答案 0 :(得分:0)

删除Console.ReadLine();正如您在ForEach循环中一样。如果您仍希望Console.ReadLine();将其移出foreach

Console.ReadLine();等待用户输入,输入任何值后,您应该会看到下一个网址。