[英]Anglesharp get node text after DoClick()
I have an HTML code: 我有一个HTML代码:
<div class="contact-button link-phone {'path':'phone', 'id':'gtziy', 'id_raw': '243468578'} atClickTracking contact-a"
data-rel="phone">
<i data-icon="phone"></i>
<strong class="xx-large">HIDDEN TEXT HERE</strong>
<span class="spoiler">SHOW</span>
</div>
I am getting the div using this code: 我使用以下代码获取div:
IHtmlElement nodeToClick = (IHtmlElement)document.All.First(m =>
m.HasAttribute("class") &&
m.ClassList.Contains("contact-button") &&
m.HasAttribute("data-rel") &&
m.GetAttribute("data-rel") == "phone");
And then I click the node using DoClick(): 然后,我使用DoClick()单击该节点:
nodeToClick.DoClick();
The HTML code of the div should change to this: div的HTML代码应更改为:
<div class="contact-button link-phone {'path':'phone', 'id':'gtziy', 'id_raw': '243468578'} atClickTracking contact-a activated"
data-rel="phone">
<i data-icon="phone"></i>
<strong class="xx-large">TEXT HERE</strong>
<span class="spoiler" style="display: none;">SHOW</span>
</div>
But the nodeToClick.TextContent
returns me the same value as it was before nodeToClick.DoClick()
. 但是nodeToClick.TextContent
我返回的值与nodeToClick.DoClick()
之前的值相同。
What I tried to do: 我试图做的是:
Thread.Sleep(2000)
before logging `nodeToClick.TextContent' 在记录`nodeToClick.TextContent'之前插入一个延迟Thread.Sleep(2000)
。 Reload HTML of the page using this piece of code: 使用以下代码重新加载页面的HTML:
public static string GetHTML(string url) { HttpWebRequest proxy_request = (HttpWebRequest)WebRequest.Create(url); proxy_request.Method = "GET"; proxy_request.ContentType = "application/x-www-form-urlencoded"; proxy_request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5"; proxy_request.KeepAlive = true; HttpWebResponse resp = proxy_request.GetResponse() as HttpWebResponse; string html = ""; using (StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)) { html = sr.ReadToEnd(); sr.Close(); } resp.Close(); html = html.Trim(); return html; }
But none of this worked for me . 但是这些都不适合我 。
How do I get the new TextContent of the element I clicked at? 如何获取单击的元素的新TextContent?
I am confused why anything should happen when you click a div
. 我很困惑为什么单击div
时会发生任何事情。 What you are missing to post is your AngleSharp configuration. 您缺少要发布的是AngleSharp配置。
I think you guess that AngleSharp comes with JS support - it does not. 我想您猜想AngleSharp附带了JS支持-事实并非如此。 AngleSharp itself is just a browser engine core - it comes with all the connection points and the most basic features, eg, an HTML5 parser. AngleSharp本身只是浏览器引擎的核心-它具有所有连接点和最基本的功能,例如HTML5解析器。 There is another library for bringing JS support - but its very rudimentary / experimental and potentially does not work in your case. 还有另一个库可以提供JS支持-但是它非常初级/实验性的,可能不适用于您的情况。
Also I would assume that since you are downloading the HTML in your own code the JS would not work anyway (you need to use AngleSharp like a browser - a browser you also do not give HTML, but an URL and the browser does the rest - with AngleSharp its the same and the thing to use here is called BrowsingContext
). 我还要假设,因为您正在以自己的代码下载HTML,所以JS仍然无法正常工作(您需要像浏览器一样使用AngleSharp-浏览器也未提供HTML,但URL则由浏览器提供,其余的-与AngleSharp相同,这里使用的东西称为BrowsingContext
)。
Long story short. 长话短说。 You cannot just click something static and expect something dynamic to happen. 您不能只单击静态的东西而期望动态的东西发生。 Also you should read the documentation of AngleSharp carefully - I guess it could help. 另外,您应该仔细阅读AngleSharp的文档 -我想它可能会有所帮助。
HTH! HTH!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.