shadonar
shadonar

Reputation: 1194

c# parse javascript content

So I have a web scraping project where one of the pages has all the necessary content in JSON format inside a set of <script> tags.

here's an example of said <script> tags:

<script>
  window.postData = {}
  window.postData["content"] = [json content]
</script>

I've used the HtmlAgilityPack to get to the particular <script> tags, but I am not sure how to grab just the json content from this. I can parse the JSON with JSON.net or other library/framework, so I'm not worried about that part. I'm just stuck on getting just the Json. Is there a javascript parsing library or something that I can use to get this, or is there another way to accomplish this.

Any help would be greatly appreciated!

Upvotes: 2

Views: 1774

Answers (1)

kavun
kavun

Reputation: 3381

Check out jint

var postDataJSON = new Engine()
    .Execute("window.postData = {}; window.postData['content'] = [json content]")
    .GetValue("window.postData");

Upvotes: 3

Related Questions