Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute HTML Javascript from Command Line

I have a number of web pages that I am attempting to parse information from obtained using curl. Each of the page uses JQuery to transform its content upon the document being loaded in the browser (using the document.ready function) - mostly setting the classes/ids of divs. The information is much easier to parse once the Javascript functions have been loaded.

What are my options for (preferably from the command line) executing the Javascript content of the pages and dumping the transformed HTML?

like image 935
mmccomb Avatar asked Dec 07 '25 09:12

mmccomb


1 Answers

To scrape dynamic web, don't use static download tools like curl.

If you want to scrape dynamic web use a headless webbrowser which you can control from your programming language. The most popular tool for this is Selenium

http://code.google.com/p/selenium/

With Selenium you can export modified DOM tree out of the browser as HTML.

An example use case:

https://stackoverflow.com/a/10053589/315168

like image 190
Mikko Ohtamaa Avatar answered Dec 08 '25 23:12

Mikko Ohtamaa