How to read JavaScript object with XPath/HTMLAgilityPack

后端 未结 1 509
独厮守ぢ
独厮守ぢ 2021-01-24 05:26

For my crawler project, I need to get product details from JavaScript object.

How can I effectively get object details from the following JavaScript? I Use XPath and HTM

相关标签:
1条回答
  • 2021-01-24 05:37

    Since the HTML Agility Pack doesn't evaluate any of the contents of the HTML, the javascript code should just be considered plain text. Use the SelectSingleNode method to find the piece of Javascript, then just grab the InnerHtml to get to the contents.

    Either find a C# javascript parser (Iron JS for example) or write a parser using standard text manipulation techniques (String.* or Regex to extract the bits you're after.

    Once you have the bits between the curly brackets you could parse them using a before mentioned parser or a library like Json.NET, since the pieces between the curly brackets seems to be valid json.

    0 讨论(0)
提交回复
热议问题