我使用HtmlAgilityPack解析网站上的值,但我的编程不运行

本文关键字:我的 编程 运行 HtmlAgilityPack 网站 | 更新日期: 2023-09-27 18:10:26

我在mp3.zing网站上写了一个编程获取值。但HtmlAgilityPack错误。我的代码如下:

string trave = "";          
String url = "http://mp3.zing.vn/bang-xep-hang/bai-hat-Viet-Nam/IWZ9Z08I.html";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlWeb a = new HtmlWeb();
doc = a.Load(url);
HtmlNodeCollection t =doc.DocumentNode.SelectNodes("//a[@class='"txtprimary'"]");
foreach (var i in t){ trave += i.InnerText; }

错误的形象http://postimg.org/image/5uuqby5ov/

我使用HtmlAgilityPack解析网站上的值,但我的编程不运行

您的代码中存在一些问题。

1-下载压缩后的内容

2-选择正确的锚。

String url = "http://mp3.zing.vn/bang-xep-hang/bai-hat-Viet-Nam/IWZ9Z08I.html";
var data = new WebClient().DownloadData(url);
var html =  new StreamReader(new GZipStream(new MemoryStream(data), CompressionMode.Decompress)).ReadToEnd();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var t = doc.DocumentNode.SelectNodes("//a[@class='txt-primary']")
        .Select(a => a.InnerText)
        .ToList();
输出:

["Chư包Giờ"、"Ấn螺母Nhớ…ThảGiấc Mơ"、"我(Vang安ĐĐ","2","Vợ安新人道"、"Buong","说你做的","孤独","Đẹp火车Thi Mớ我公司简介:ềuĐứ》","ThếGiớ我Ảo》见到ật","吉尔Như","Đơn Phương","郎君》(川崎安Em)","我Khong PhảDạng VừĐ盟","安La củEm"、"Buong"、"Khuon MặtĐang Thương"、"ngườ》我từng安Rất分nặng","cứThế孟淑娟Chờ","PhốThị"、"Thật Bấngờ"、"凸轮Ơn Vi tất cả"、"Em La củ安","鑫Đừng Buong茶"、"Chạy(路上)","人工智能Cũng公司Nỗ我BuồN","梅Luon GầN Nhau"、"VẫN C》ứEm","我T Lờỏ河静","Vợ》","反对NợMẹ","安Khong圣Đ盟","反对Đường钢铁洪流","Khong有限公司新兴市场","我的一切","曹NhữngĐềuĐ作为","Khong星期四ộC VềNhau"、"Em Củ作为Khứ","ĐộCẨM","公司Lẽ")

相关文章: