• 使用HtmlAgilityPack抓取Ethereum Tokens信息


    使用HtmlAgilityPack抓取Ethereum Tokens信息

        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    for (int i = 1; i <= 11; i++)
                    {
                        string url = "https://etherscan.io/tokens?p="+i;
                        HtmlWeb webClient = new HtmlWeb();
                        HtmlDocument doc = webClient.Load(url);
    
                        var tbody = doc.DocumentNode.SelectSingleNode("//*[@id='ContentPlaceHolder1_divresult']/table/tbody");
                        var trItems = tbody.SelectNodes("tr");
                        foreach (var tr in trItems)
                        {
                            try
                            {
                                var tdItems = tr.SelectNodes("td");
                                string id = tdItems[0].SelectSingleNode("b//span").InnerHtml.Replace(" ", "");
                                string contractAddress = tdItems[1].SelectSingleNode("a").Attributes["href"].Value.Replace("/token/", "");
                                string tokenLogo = "https://etherscan.io" + tdItems[1].SelectSingleNode("a/img").Attributes["src"].Value;
                                string temp = tdItems[2].SelectSingleNode("h5/a").InnerHtml;
                                string tokenName = temp.Substring(0, temp.IndexOf(" "));
                                string tokenSymbol = temp.Substring(temp.IndexOf("(") + 1, temp.IndexOf(")") - temp.IndexOf("(") - 1);
                                string tokenDescribe = tdItems[2].SelectSingleNode("small/font").InnerHtml;
    
                                string tokenUrl = "https://etherscan.io/token/" + contractAddress;
                                HtmlWeb webtokenClient = new HtmlWeb();
                                HtmlDocument tokendoc = webtokenClient.Load(tokenUrl);
                                string tokenDecimal = tokendoc.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[5]/div[1]/div[2]/table[1]/tr[2]/td[2]").InnerHtml.Replace("
    ", "");
                                Console.WriteLine($"{id}	{contractAddress}	{tokenSymbol}	{tokenDecimal}	{tokenName}	{tokenLogo}	{tokenDescribe}	");
                            }
                            catch (Exception ex)
                            {
    
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                Console.Read();
            }
        }
    

  • 相关阅读:
    codeforces 560 B. Gerald is into Art (模拟)
    导航控制器属性和基本使用
    多控制器和导航控制器简单介绍
    SQLite数据库框架--FMDB简单介绍
    数据库sqlite3的使用-ios中引用方法
    数据库sqlite3的使用-代码实例应用
    数据库sqlite3的使用-基本语法
    数据库sqlite3的使用-Navicat的安装
    如何制作.a静态库?合成多架构静态库?
    苹果Instruments/Shark性能调试工具概述
  • 原文地址:https://www.cnblogs.com/heyangyi/p/9253645.html
Copyright © 2020-2023  润新知