请原谅我在这个问题上的无知
我正在使用
string p="http://" + Textbox2.text;
string r= textBox3.Text;
System.Net.WebClient webclient=new
System.Net.Webclient();
webclient.DownloadFile(p,r);下载网页。您可以帮助我增强代码,使其下载整个网站。尝试使用超文本标记语言屏幕抓取,但它只返回index.html文件的href链接。我该如何继续?
谢谢
发布于 2010-01-19 15:21:51
抓取一个网站实际上是一项很大的工作,有很多的角落案例。
改为调用wget。manual解释了如何使用"recursive retrieval“选项。
发布于 2010-01-19 16:38:29
protected string GetWebString(string url)
{
string appURL = url;
HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as HttpWebRequest;
HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
StreamReader srResponseReader = new StreamReader(hwrWebResponse.GetResponseStream());
string strResponseData = srResponseReader.ReadToEnd();
srResponseReader.Close();
return strResponseData;
}这会将网页放入所提供的URL中的字符串中。
然后,您可以使用REGEX来解析字符串。
这个小片段从craigslist中获取特定的链接,并将它们添加到你想要的arraylist...Modify中。
protected ArrayList GetListings(int pages)
{
ArrayList list = new ArrayList();
string page = GetWebString("http://albany.craigslist.org/bik/");
MatchCollection listingMatches = Regex.Matches(page, "(<p><a href=\")(?<LINK>/.+/.+[.]html)(\">)(?<TITLE>.*)(-</a>)");
foreach (Match m in listingMatches)
{
list.Add("http://albany.craigslist.org" + m.Groups["LINK"].Value.ToString());
}
return list;
}https://stackoverflow.com/questions/2091758
复制相似问题