【发布时间】:2015-08-22 04:15:30
【问题描述】:
网页使用 javascript 来构建它的 html,所以我需要支持 js 的 html 解析器。
我找到了anglesharp,但我不能让它工作。
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);
}
}
}
【问题讨论】:
-
可能想看看PhantomJS
-
PhantomJS 是一个带有 js api 的外部应用程序。此外,一些防病毒软件将其视为威胁并显示丑陋的警告弹出窗口。
标签: javascript c# web-scraping anglesharp