private void button1_Click(object sender, EventArgs e)
{
test();
}
public void test()
{
Dictionary<string, string> LnksDict = new Dictionary<string, string>();
using (SmartWebClient smwc = new SmartWebClient())
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(smwc.DownloadString("http://www.google.com/adplanner/static/top1000/"));
var links = htmlDoc.DocumentNode
.Descendants("a").Select(x => x.Attributes["href"]);
foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a"))
{
var UrlVal= link.Attributes["href"].Value;
var name = UrlVal.Split('.')[1];
LnksDict.Add(name, UrlVal);
}
}
}
#region <<=========== SmWbCl ============>>
public class SmartWebClient : WebClient
{
private readonly int maxConcurentConnectionCount;
public SmartWebClient(int maxConcurentConnectionCount = 20)
{
this.maxConcurentConnectionCount = maxConcurentConnectionCount;
}
protected override WebRequest GetWebRequest(Uri address)
{
var httpWebRequest = (HttpWebRequest)base.GetWebRequest(address);
if (httpWebRequest == null)
{
return null;
}
if (maxConcurentConnectionCount != 0)
{
this.Proxy = null;
this.Encoding = Encoding.GetEncoding("UTF-8");
httpWebRequest.ServicePoint.ConnectionLimit = maxConcurentConnectionCount;
}
return httpWebRequest;
}
}
#endregion
在這段代碼中,我試圖構建一個列表,以便稍後用作自動完成源的URL。填充字典與鏈接通過HtmlAgility&自定義webclient
我做錯了什麼是notc onditioning添加到字典中的解析值。
我需要找到一個方法來添加域名爲重點,即使已經存在,
,所以我希望能夠做一個條件:
如果在這個字典中的key
已經存在,加上目前link
的collection index
到string.value
key
的作爲後綴
,或者如果你想提出一個不同的解決方案都在一起......我會很高興看到新的榜樣。 謝謝
第一個爲什麼你不睡覺在這個小時(:我在這裏,只要我醒着..(第二,我看到,每一個新的簡單任務,我想達到的結果我突然有5個新對象研究(:('HashSet'),第三和最後我想感謝你一個非常好解釋的答案!!希望在你有時間在我的帖子中回答「花費」時見到你。 – LoneXcoder