comment obtenir le code d'élément inspecté à l'aide de c #

c# html-agility-pack

Question

Je souhaite obtenir du texte à partir d'une URL, mais le texte ne s'affiche pas dans le code source. Je peux le voir seulement dans l'élément inspecter. Y at-il de toute façon, en C # pour obtenir le contenu de l'élément inspecter de la page. J'essaie htmlagilitypack avec c # mais donne une exception nulle.

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);

Réponse populaire

C'est une sorte de données cryptées qui sont chargées dynamiquement après le chargement de la page. L'URL récupérant lesdites données est:

http://www.whatsonindia.com/appi/user?channelgenre=all&context=applicationname%3Dsourcebits%3Bheadendid%3D0&dateselected=0&mode=getTV

Il contient un nœud "data" et un "pki" au format JSON. Vous ne pouvez pas simplement répondre en attendant que la page soit complètement chargée.

Au lieu de cela, vous pouvez simplement faire une demande à l’URL donnée et déchiffrer le texte. C'est la seule façon que je puisse assumer ici. La méthode peu fiable consiste à charger l'URL dans un contrôle de navigateur Web et à attendre quelques secondes (par exemple 5 à 10) en supposant que tout le contenu est chargé, puis à analyser le contrôle DocumentText ou le navigateur Web.

J'ai réussi à obtenir ces données JSON pour les programmes télévisés:

{
"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"
      }
    ]
  }
}

Il utilise CryptoJS pour le cryptage et le décryptage.




Sous licence: CC-BY-SA with attribution
Non affilié à Stack Overflow
Est-ce KB légal? Oui, apprenez pourquoi
Sous licence: CC-BY-SA with attribution
Non affilié à Stack Overflow
Est-ce KB légal? Oui, apprenez pourquoi