简体   繁体   中英

I want to parse this website url "https://www.171chryslerdodgejeepram.com/" to get value of DealerId but I have no idea how to do it

foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//script").Where(x => x.InnerHtml.Contains("DealerId:")))
{


}

I am trying to get value of dealer id with the help of above code but it is not returning anything, but if you trying to find DealerId from page source of above website then it is there. please help me to achieve this or if anything wrong with above code then please correct me.

  1. you can parse JS code with something like ( https://github.com/sebastienros/jint ) and extract the field you need from JS object
  2. you can simple find this text (not elegant, but works):

UPD1: regex version

    static void Main(string[] args)
    {
        var url = "https://www.171chryslerdodgejeepram.com/";
        var web = new HtmlWeb();
        var doc = web.Load(url);

        foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//script").Where(x => x.InnerHtml.Contains("dealerId:")))
        {
            var s = node.InnerText;
            Regex r = new Regex(@"dealerId:\s+'(\d+)'");
            Match m = r.Match(s);
            Console.WriteLine(m.Groups[1].Value);
        }

        Console.ReadKey();
    }
 var url = "https://www.171chryslerdodgejeepram.com/";
        var web = new HtmlWeb();
        var doc = web.Load(url);
 foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//script").Where(x => x.InnerHtml.ToLower().Contains("dealerid")))
                {
                    AdwordsAccount info = new AdwordsAccount();
                    var s = node.InnerText;
                    //Regex r = new Regex("dealerid(.*?)\",");
                    Regex r = new Regex(@"dealerId:\s+'(\d+)'");
                    Match m = r.Match(s.ToLower());
                    info.account = m.Groups[1].Value;
                    urlinfo.adwordsaccount.Add(info);
                }

@cereberus this is my code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM