우선 C# 및 Windows 8 앱을 처음 사용한다고 말하고 싶습니다. 그러니 제발, 제발 열심히하지 마세요.Html Agility Pack을 Windows 8 앱과 함께 사용하는 방법?
일부 이미지 URL을 추출하고 XML 파일로 저장하려면 다음 코드를 작성하십시오. Html Agility Pack을 사용하고 있지만 Windows 8 응용 프로그램에서 코드를 사용하려고하면 작동하지 않습니다. 나는 여기에서 Fizzler Html Agility Pack을 사용해야 만한다는 것을 알고있다 : http://fizzlerex.codeplex.com/releases/view/89833하지만 나는 틀렸다는 것을 모른다. 나는 비주얼 스튜디오 2012을 사용하고 있으며 다음 요소를 인식하지 못하는
***WebClient*** x = new ***WebClient***();
***XmlDocument*** output = new ***XmlDocument***();
***XmlElement*** imgElements = output.CreateElement("ImgElements");
foreach(HtmlNode link in document.***DocumentElement***.SelectNodes("//img[contains(@src, '_412s.jpg')]"));
***out***.Save(@"C:\test.xml");
코드 :
using HtmlAgilityPack;
using Fizzler;
using Fizzler.Systems.HtmlAgilityPack;
using System.Xml;
public void Images()
{
WebClient x = new WebClient();
string source = x.DownloadString(@"http://www.google.com");
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.Load(source);
XmlDocument output = new XmlDocument();
XmlElement imgElements = output.CreateElement("ImgElements");
output.AppendChild(imgElements);
foreach(HtmlNode link in document.DocumentElement.SelectNodes("//img[contains(@src, '_412s.jpg')]"))
{
XmlElement img = output.CreateElement(link.Name);
foreach(HtmlAttribute a in link.Attributes)
{
img.SetAttribute(a.Name, a.Value);
}
imgElements.AppendChild(img);
}
out.Save(@"C:\test.xml");
}
당신이 좀 도와 주실 수 있습니까?
감사합니다.
나는 outline.Save에 out.Save 변경했다. WebClient는 Windows 8 응용 프로그램에서 인식되지 않으므로 HttpClient로 변경했지만 지금은 DownloadString이 더 이상 작동하지 않습니다. client.GetAsync를 사용하여 변경해야한다고 생각합니다. 또한 DocumentNode로 DocumentElement를 변경해야했습니다. GetAsync 함수를 도와 주시겠습니까? –