Obtain javascript result

Michael Torrie torriem at gmail.com
Fri Oct 21 14:37:19 EDT 2016


On 10/21/2016 07:29 AM, eproser at gmail.com wrote:
> Hello NG.
> 
> I'm new in Python for fun.
> 
> I have a html page (I load it by BeautifulSoap) that contain
> also this javascript code:
> ...
> <script language="javascript">
>   $(document).ready(function() {
>     matchdetails_init('rLu2Xsdi', '1x2');
>   });
> </script>
> ...
> Please, can You me to aim on the right way
> to obtain into a Python data structure 
> everything that JS code give back to browser.

All BeautifulSoup does is parse html. It doesn't run javascript.  To
obtain the html after the javascript has run, or to interact with the
Javascript you'll need a tool like Selenium[1], which has drivers for
Python and also Chrome or Firefox.  In other words you need a real
browser running that can execute the javascript.  After that you can
extract the html results using BeautifulSoup.

Google for many tutorials on using Selenium with python.

[1] https://pypi.python.org/pypi/selenium



More information about the Python-list mailing list