关于C# 使用Xpath路径(HtmlAgilityPack)对网页内容查找获取的方法。(程序为.ashx的一般处理程序)

本文介绍如何使用C#结合HtmlAgilityPack库,通过XPath表达式解析网页内容。以具体的代码示例展示了如何定位并获取表格中的特定数据,特别是针对隐藏在多个嵌套表格中的信息,以及如何找到包含特定汉字的TR元素,并提取TD内的内容。
摘要由CSDN通过智能技术生成

先贴代码:

using System;
using System.Web;
using Newtonsoft.Json;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using HtmlAgilityPack;

namespace Lesson1
{
    /// <summary>
    /// ZZ_SY 的摘要说明
    /// </summary>
    public class ZZ_SY : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string url = context.Request["url"];
            int id = 0;
            
            #region id = 16  http://www.huadanseed.cn/huadan/ProductShow.asp?ID=169    Xpath 路径在每个客户端显示不一样
            if (id == 16)
            {
                string xpath_table = "//tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table[1]"; 
                HtmlNodeCollection node_table = doc.DocumentNode.Sel
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值