Wie man Elementcode mit c # inspizieren kann

c# html-agility-pack

Frage

Ich möchte Text von URL erhalten, aber Text wird nicht im Quellcode angezeigt. Ich kann es nur im inspect-Element sehen. Gibt es sowieso, in C # den Inhalt des Inspect Elements der Seite zu bekommen. Ich versuche htmlagilitypack mit c #, gebe aber null Ausnahme.

Class1 class1obj = new Class1(); 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);  
request.Method = "GET"; 
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
if (response.StatusCode == HttpStatusCode.OK) 
{ 
    Stream receiveStream = response.GetResponseStream(); 
    StreamReader readStream = null; 
    if (response.CharacterSet == null)
        readStream = new StreamReader(receiveStream); 
    else
        readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); 
    class1obj.Data1 = readStream.ReadToEnd(); 
    Console.WriteLine(class1obj.Data1);
    readStream.Close();
 }

 HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
 doc.LoadHtml(class1obj.Data1);
 // HtmlNodeCollection tables2 =     doc.DocumentNode.SelectNodes(".//div[@class='tv_ch_detila h_scroll_detail']");
 HtmlNode rows2 = doc.DocumentNode.SelectSingleNode(".//div[@class='sub_text']");
 Console.WriteLine(rows2.InnerText);

Beliebte Antwort

Es handelt sich um verschlüsselte Daten, die dynamisch geladen werden, nachdem die Seite geladen wurde. Die URL, die die genannten Daten erhält, lautet:

http://www.whatsonindia.com/appi/user?channelgenre=all&context=applicationname%3Dsourcebits%3Bheadendid%3D0&dateselected=0&mode=getTVGuideInfo&pageno=1&responseformat=json&responselanguage=English&starthour=0&totalhrdata=24&userid=-1

Es enthält einen "data" - und einen "pki" -Knoten im JSON-Format. Sie können nicht nur darauf antworten, dass Sie darauf warten, dass die Seite vollständig geladen ist.

Stattdessen können Sie einfach eine Anfrage an die angegebene URL stellen und den Text entschlüsseln. Dies ist der einzige Weg, den ich hier annehmen kann. Die unzuverlässige Methode besteht darin, die URL in ein Webbrowser-Steuerelement zu laden und einige Sekunden (etwa 5-10) zu warten, vorausgesetzt, dass alle Inhalte geladen sind und dann das DocumentText- oder Webbrowser-Steuerelement analysiert.

Ich habe es geschafft, diese JSON-Daten für TV-Programme zu bekommen:

{
"gettvguidewithgenre": {
    "tvguideprogrammewithgenrelist": [
      {
        "programmeid": "10000000934920000",
        "starttime": "2014-02-25T00:00:00+05:30",
        "endtime": "2014-02-25T01:40:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Ghatak",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549824121",
        "starttime": "2014-02-25T01:40:00+05:30",
        "endtime": "2014-02-25T03:50:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Time Limit-36 Ghante",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Drama",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549816018",
        "starttime": "2014-02-25T03:50:00+05:30",
        "endtime": "2014-02-25T05:40:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Volcano High",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549673440",
        "starttime": "2014-02-25T05:40:00+05:30",
        "endtime": "2014-02-25T08:10:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Maa Beti",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Drama",
        "Isrecommended": "1"
      },
      {
        "programmeid": "10000001008740000",
        "starttime": "2014-02-25T08:10:00+05:30",
        "endtime": "2014-02-25T11:05:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Dus",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549644318",
        "starttime": "2014-02-25T11:05:00+05:30",
        "endtime": "2014-02-25T13:55:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Money Hai Toh Honey Hai",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Comedy",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549646489",
        "starttime": "2014-02-25T13:55:00+05:30",
        "endtime": "2014-02-25T17:15:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Farz",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Drama",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549709799",
        "starttime": "2014-02-25T17:15:00+05:30",
        "endtime": "2014-02-25T20:00:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Action Replayy",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Comedy",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549664553",
        "starttime": "2014-02-25T20:00:00+05:30",
        "endtime": "2014-02-25T23:25:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Indian",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549781987",
        "starttime": "2014-02-25T23:25:00+05:30",
        "endtime": "2014-02-26T00:00:00+05:30",
        "channelid": "10000000000110000",
        "programmename": "Narsimha - Man Of Power",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Drama",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549741259",
        "starttime": "2014-02-25T00:00:00+05:30",
        "endtime": "2014-02-25T02:00:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "The Dirty Picture",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Drama",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T02:00:00+05:30",
        "endtime": "2014-02-25T02:40:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T02:40:00+05:30",
        "endtime": "2014-02-25T03:00:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T03:00:00+05:30",
        "endtime": "2014-02-25T03:25:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T03:25:00+05:30",
        "endtime": "2014-02-25T03:40:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T03:40:00+05:30",
        "endtime": "2014-02-25T04:00:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549867681",
        "starttime": "2014-02-25T04:00:00+05:30",
        "endtime": "2014-02-25T04:25:00+05:30",
        "channelid": "10000000000540000",
        "programmename": "Extraa Shots Special",
        "m2ecategoryname": "TV Show",
        "m2esubcategoryname": "Entertainment",
        "Isrecommended": "1"
      },
      {
        "programmeid": "10000001078790000",
        "starttime": "2014-02-25T18:08:00+05:30",
        "endtime": "2014-02-25T20:30:00+05:30",
        "channelid": "10000000000210000",
        "programmename": "Aadmi",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549651842",
        "starttime": "2014-02-25T20:30:00+05:30",
        "endtime": "2014-02-25T23:16:00+05:30",
        "channelid": "10000000000210000",
        "programmename": "Dum",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Action",
        "Isrecommended": "1"
      },
      {
        "programmeid": "30000000549828153",
        "starttime": "2014-02-25T23:16:00+05:30",
        "endtime": "2014-02-26T00:00:00+05:30",
        "channelid": "10000000000210000",
        "programmename": "Aakhri Baazi",
        "m2ecategoryname": "Film",
        "m2esubcategoryname": "Romance",
        "Isrecommended": "1"
      }
    ],
    "channelinfo": [
      {
        "ChannelID": "10000000000110000",
        "ChannelName": "STAR GOLD",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000110000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000540000",
        "ChannelName": "MAX",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000540000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000620000",
        "ChannelName": "TEN SPORTS",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000620000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000700000",
        "ChannelName": "HBO",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000700000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000100000",
        "ChannelName": "STAR MOVIES",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000100000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000080000",
        "ChannelName": "STAR PLUS",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000080000.png",
        "ischannelfavorite": "false"
      },
      {
        "ChannelID": "10000000000210000",
        "ChannelName": "ZEE CINEMA",
        "LCN": "0",
        "Operator_Id": "2645",
        "logofileurl": "http://images.whatsonindia.com/WhatsOnTv/Images/applicationchannellogo/10000000000210000.png",
        "ischannelfavorite": "false"
      }
    ]
  }
}

Es verwendet CryptoJS für die Verschlüsselung und Entschlüsselung.




Lizenziert unter: CC-BY-SA with attribution
Nicht verbunden mit Stack Overflow
Ist diese KB legal? Ja, lerne warum
Lizenziert unter: CC-BY-SA with attribution
Nicht verbunden mit Stack Overflow
Ist diese KB legal? Ja, lerne warum