0

我创建 aXPathDocumnet并给它 a xml file,但它不加载文档。我的意思是加载需要无穷大,因为没有例外或类似的东西。这是代码:

string root = @"http://emtehan.roshd.ir";
WebClient webclient = new WebClient();
webclient.DownloadFile(root, "doc.xml");
XPathDocument document = new XPathDocument("doc.xml");
4

2 回答 2

1

问题是您的目标站点 - 它不使用标准标签,我的意思是解析 xml 时出现问题。看来您只想从代码中提取 url。因此,使用示例 httpclient 下载行 html 内容,然后使用 ereg 函数提取 url。另外,如果你只是想偷一个网站,有很多不错的应用程序,比如 websote 离线浏览器(试用版),甚至一些开源项目(参考:google.com!)

*ereg 方法比解析所有代码要快得多!检查一些开源项目代码,它们都是这样工作的。

于 2012-05-12T16:04:48.717 回答
0

您可以参考 System.Xml.Linq.dll

代码在这里

///Reference the namespace
using System.Xml.Linq;
try
{ 
    ///Read xml from url
    var doc = XDocument.Load("MyUrl");
    ///Write it to local file
    doc.Save("MyFile.xml");
}
catch(Exception exception)
{
    MessageBox.Show(exception.Message);
}

它会解决问题吗?

已编辑

var response = HttpWebRequest.Create("http://emtehan.roshd.ir/").GetResponse() as HttpWebResponse;
var output = new StreamReader(response.GetResponseStream()).ReadToEnd();

它将 html 提供给字符串,然后您可以执行任何您想要的操作

于 2012-05-12T14:00:39.650 回答