无法使用html敏捷包XPath从网页中获取Innertexts。

发布于 01-17 21:00 字数 1826 浏览 3 评论 0 原文

这就是我的代码。 我试图将文本获取到跨度内并将其存储在本地。我使用 html 敏捷包并尝试使用 xpath 检索文本,但节点不检索任何内容并显示为 null。

这是我试图从中获取文本的页面: https://siat.sat.gob.mx/app/qr/faces/pages/mobile/validadorqr.jsf?D1=10&D2=1&D3=15030267855_SDS150309FC7 特别是“Denominacion o razón Social”文本。

namespace ObtencionDatosSatBeta
{
    public partial class Form1 : Form
    {
        DataTable table;
        public Form1()
        {
            InitializeComponent();
            
        }
        private void InitTable()
        {
            table = new DataTable("tabladedatosTable");
            table.Columns.Add("Variable", typeof(string));
            table.Columns.Add("Contenido", typeof(string));
            //table.Rows.Add("Super Mario 64", "84%");
            tabladedatos.DataSource = table;
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            InitTable();
            HtmlWeb web = new HtmlWeb();
            var doc = await Task.Factory.StartNew(() => web.Load("https://siat.sat.gob.mx/app/qr/faces/pages/mobile/validadorqr.jsf?D1=10&D2=1&D3=15030267855_SDS150309FC7"));
            var nodes = doc.DocumentNode.SelectNodes("//*[@id=\"ubicacionForm: j_idt12:0:j_idt13: j_idt17_data\"]//tr//td//span");
            var innerTexts = nodes.Select(node => node.InnerText);
            
        }

        private void tabladedatos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

有什么想法吗?

var nodes = doc.DocumentNode.SelectNodes("//*[@id=\"ubicacionForm: j_idt12:0:j_idt13: j_idt17_data\"]//tr//td//span");

上面的代码行是显示为 null 的代码行。

So this is my code guys.
Im trying to get the text inside a span and storage it locally. Im using html agility pack and trying to retrieve the text using xpath but the nodes dont retrieve anything and appear as null.

This is the page im trying to get the text from: https://siat.sat.gob.mx/app/qr/faces/pages/mobile/validadorqr.jsf?D1=10&D2=1&D3=15030267855_SDS150309FC7
Specifically the "Denominación o razón social" text.

namespace ObtencionDatosSatBeta
{
    public partial class Form1 : Form
    {
        DataTable table;
        public Form1()
        {
            InitializeComponent();
            
        }
        private void InitTable()
        {
            table = new DataTable("tabladedatosTable");
            table.Columns.Add("Variable", typeof(string));
            table.Columns.Add("Contenido", typeof(string));
            //table.Rows.Add("Super Mario 64", "84%");
            tabladedatos.DataSource = table;
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            InitTable();
            HtmlWeb web = new HtmlWeb();
            var doc = await Task.Factory.StartNew(() => web.Load("https://siat.sat.gob.mx/app/qr/faces/pages/mobile/validadorqr.jsf?D1=10&D2=1&D3=15030267855_SDS150309FC7"));
            var nodes = doc.DocumentNode.SelectNodes("//*[@id=\"ubicacionForm: j_idt12:0:j_idt13: j_idt17_data\"]//tr//td//span");
            var innerTexts = nodes.Select(node => node.InnerText);
            
        }

        private void tabladedatos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

Any idea?

var nodes = doc.DocumentNode.SelectNodes("//*[@id=\"ubicacionForm: j_idt12:0:j_idt13: j_idt17_data\"]//tr//td//span");

The line of code above is the one that appears as null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆° 2025-01-24 21:00:57

使用此XPath在元素下获得以下ID的第一个跨度:ubicacionform:j_idt10:0:j_idt11:j_idt14_data

(//*[@id='ubicacionForm:j_idt10:0:j_idt11:j_idt14_data']//span)[1]

您可以通过在chrome中复制html(ctrl + option + j)

然后将HTML粘贴到Xpather中,您可以在其中玩XPath。 xpather.com

Use this Xpath which gets the first span under the element with the following ID: ubicacionForm:j_idt10:0:j_idt11:j_idt14_data

(//*[@id='ubicacionForm:j_idt10:0:j_idt11:j_idt14_data']//span)[1]

You can select the element using multiple different ways by copying the HTML in chrome (Ctrl + Option + J)

enter image description here

And then paste the HTML in Xpather where you can play around with your Xpath. Xpather.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文