zoukankan      html  css  js  c++  java
  • 使用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();
            }
        }
    

  • 相关阅读:
    iOS-MVC设计模式
    LoadRunner中文转码
    LoadRunner中Base64编码解码
    jmeter持续集成化(一)---jmeter+Ant+DOS构建执行脚本
    LoadRunner MD5加密
    Jmeter元件--BeanShell Timer
    ftp上传下载
    Shell编程实例
    Oracle数据库sqlplus操作
    oracle执行计划分析
  • 原文地址:https://www.cnblogs.com/heyangyi/p/9253645.html
Copyright © 2011-2022 走看看