【发布时间】:2021-09-26 11:57:44
【问题描述】:
这是我尝试选择的屏幕截图,我从控制台复制了 Xpath,但是当我运行程序时,它指出它是 null:Anchor tag。
我尝试将 Xpath 复制到标签以及它上面的标签,它们都返回一个空值,但是当我在浏览器中运行查询并检查页面时,它们都有一个值。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;
namespace AccessID2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
#region UI Event Handlers
private void cmdGo_Click(object sender, EventArgs e)
{
RestClient rClient = new RestClient();
rClient.endPoint = txtUrl.Text;
debugOutput("Searching for Product");
string strResponse = string.Empty;
strResponse = rClient.makeRequest();
debugOutput(strResponse);
var html = strResponse;
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(html);
var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//*[@id='anch_114']");
txtID.Text = htmlNodes.ToString();
}
#endregion
private void debugOutput(string strDebugText)
{
try
{
System.Diagnostics.Debug.Write(strDebugText + Environment.NewLine);
txtResponse.Text = txtResponse.Text + strDebugText + Environment.NewLine;
txtResponse.SelectionStart = txtResponse.TextLength;
txtResponse.ScrollToCaret();
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.Message, ToString() + Environment.NewLine);
}
}
private void label3_Click(object sender, EventArgs e)
{
}
}
}
【问题讨论】: