网页使用
javascript来构建其html所以我需要支持js的html解析器.
我发现了角度锐利,但我不能让它起作用.
我发现了角度锐利,但我不能让它起作用.
- using AngleSharp;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace AngleSharpScraping
- {
- class Program
- {
- static void Main(string[] args)
- {
- GetMkvToolNix();
- Console.ReadKey();
- }
- static async void GetMkvToolNix()
- {
- // Create a new configuration with javascript interpreter.
- var config = new Configuration().WithJavaScript();
- // Parsing process.
- var document = await BrowsingContext.New(config).OpenAsync(Url.Create("http://www.fosshub.com/MKVToolNix.html"));
- var link = document.QuerySelector("body > div.container.page-content > div > div.col-sm-9 > article > div.main-dl-Box > p:nth-child(2) > a.dwl-link.xlink").GetAttribute("data");
- Console.WriteLine(link);
- }
- }
- }
解决方法
AngleSharp是一个文本解析器.如果你想用JS抓取动态网页,你需要一个无头浏览器.
This answer提供了几个选项(至少一个免费和开源:WebKit.NET).