谁能帮助我如何获取此网站数据? [英] Can anyone help me how to fetch this web site data ?

查看:69
本文介绍了谁能帮助我如何获取此网站数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下链接:

LINK

我尝试了我的代码,无法获取表数据,因为它没有表ID,并且带有一些棘手的代码(我认为),这是我的代码:

I tried my code, cannot get the table data, because it do not have table id and with some tricky code (I think), here is my code: 

 static void Main(string[] args)
        {
            HtmlWeb webClient = new HtmlWeb();

            HtmlAgilityPack.HtmlDocument doc = webClient.Load("http://racing.hkjc.com/racing/Info/Meeting/Results/English/Local/20161116/HV/3");
            HtmlNode table = doc.DocumentNode.SelectSingleNode("//table");
        

                var cells = (from cell in table.SelectNodes("./tr")
                             select cell.InnerText).ToList();

            foreach (var cell in cells)

            {
                Console.Write(cell);
                Console.ReadKey();
            }

有人知道如何从此页面获取数据吗?以及使用它的任何棘手的代码?

Anyone know how to get the data from this page ? and any tricky code it using ?

非常感谢


推荐答案

WKCALVIN,

Hi WKCALVIN,

谢谢您在这里发布.

对于您的问题,您可以使用F12从网站上的表格中获取信息.

For your question, you could use F12 to get the information from the table in your website.

这是在键盘上单击F12后的屏幕截图.

Here is the screenshot after click F12 in your keyboard.

我使用代码获取此表的值.

I use the code to get the value of this table.

请尝试以下代码.我尝试过这个.效果很好.

Please try the following code. I tried it. It works well.

using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace get_table_from_website
{
    class Program
    {
        static void Main(string[] args)
        { 
            WebClient webClient = new WebClient();
            string page = webClient.DownloadString("http://racing.hkjc.com/racing/Info/Meeting/Results/English/Local/20161116/HV/3");

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(page);

            List<List<string>> table = doc.DocumentNode.SelectSingleNode("//table[@class='tableBorder trBgBlue tdAlignC number12 draggable']")
                        .Descendants("tr")
                        .Skip(1)
                        .Where(tr => tr.Elements("td").Count() ==12)
                        .Select(tr => tr.Elements("td").Select(td => td.InnerText.Trim()).ToList())
                        .ToList();           
        }
    }

}

我用gif显示结果.

我希望这会对您有所帮助.

I hope this would be helpful to you.

如果还有其他问题,请随时与我们联系.

If you have something else, please feel free to contact us.

最好的问候,

温迪


这篇关于谁能帮助我如何获取此网站数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆