@
zhujinliang ```
//一个采集程序 goto 代替递归
public void Run(string listurl)
{
using (var wc = new WebClient())
{
loop:
string html = Encoding.GetEncoding("utf-8").GetString(wc.DownloadData(listurl));
var doc = new HtmlDocument();
doc.LoadHtml(html);
var nodes = doc.DocumentNode.SelectNodes("//ul[@id=\"data_list\"]/li/div/a");
for (int i = 0; i < nodes.Count; i++)
{
var node = nodes[i];
string link = "http://www..cn" + node.Attributes["href"].Value;
string title = node.SelectSingleNode("span[@class=\"sTit\"]").InnerText;
Save(title, link);
}
var nextnode = doc.DocumentNode.SelectSingleNode("//div[@class='page mb clearfixs']/em/following-sibling::a");
if (nextnode != null)
{
listurl = "http://www..cn" + nextnode.Attributes["href"].Value;
goto loop;
}
}
}
//如果使用递归
public void Run(string listurl)
{
using (var wc = new WebClient())
{
string html = Encoding.GetEncoding("utf-8").GetString(wc.DownloadData(listurl));
var doc = new HtmlDocument();
doc.LoadHtml(html);
var nodes = doc.DocumentNode.SelectNodes("//ul[@id=\"data_list\"]/li/div/a");
for (int i = 0; i < nodes.Count; i++)
{
var node = nodes[i];
string link = "http://www..cn" + node.Attributes["href"].Value;
string title = node.SelectSingleNode("span[@class=\"sTit\"]").InnerText;
Save(title, link);
}
var nextnode = doc.DocumentNode.SelectSingleNode("//div[@class='page mb clearfixs']/em/following-sibling::a");
if (nextnode != null)
{
var nexturl = "http://www..cn" + nextnode.Attributes["href"].Value;
Run(nexturl);
}
}
}
```