使用htmlagilitypack从浏览器加载

时间:2018-03-07 10:39:02

标签: c# web browser html-agility-pack

目前,我试图从htmlaglitypack官方网站上运行示例,但此代码已损坏:http://html-agility-pack.net/from-browser

我想在脚本完成后提取内容。我的代码:

do $$
    declare
    m text[];
    a text[] := array[['cabinet1003052234'], ['cabinet1027326445'], ['cabinet1062828216'], ['cabinet108034857']];
    s text;
begin
FOREACH m SLICE 1 IN ARRAY a LOOP
execute format('select count(*) from %I.react_order', CAST (m[1] AS regnamespace)) into s;
    raise info '%: %', m,s;
end loop;
end;
$$
;

private void button1_Click(object sender, EventArgs e) { string url = "http://html-agility-pack/from-browser"; var web2 = new HtmlWeb(); var doc2 = web2.LoadFromBrowser(url, html => { return !html.Contains("<div id=\"uiDynamicText\"></div>"); }); var t2 = doc2.DocumentNode.SelectSingleNode(".//div[@id='uiDynamicText']"); listBox1.Items.Add("Text 2: " + t2.InnerHtml + t2.OuterHtml); } 保持为null。有什么问题?

2 个答案:

答案 0 :(得分:0)

website说要使用:

filtering=[{field:"campaign.name",operator:"CONTAIN",value:"Uncle"}

您使用的是不同的代码:

var t2 = doc2.DocumentNode.SelectSingleNode("//div[@id='uiDynamicText']").InnerText;

这解释了为什么,使用您的代码,var t2 = doc2.DocumentNode.SelectSingleNode(".//div[@id='uiDynamicText']"); t2

答案 1 :(得分:0)

HAP代码还具有错误的URL(缺少“ .net”),因此该代码应显示为 字符串url =“ https://html-agility-pack.net/from-browser”;