我有一个 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>
我正在使用以下代码获取 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");
然后我使用 DoClick() 单击节点:
nodeToClick.DoClick();
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>
但是nodeToClick.TextContent
返回的值与以前相同nodeToClick.DoClick()
。
我试图做的事情:
Thread.Sleep(2000)
在记录“nodeToClick.TextContent”之前插入延迟- 延迟 2 秒后重写 nodeToClick 而不更新页面
使用这段代码重新加载页面的 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; }
但这些都不适合我。
如何获取我单击的元素的新 TextContent?