Skip to content
Advertisement

Accessing Data from Javascript API call [closed]

I am trying to access the data shown on this website: Link using either python requests or requests-html. The site calls this API: API

I’ve tried copying the POST request using Insomnia (Copying cURL). I get a response code 200 but an error saying “Error getting base data: Error parsing xmlsquery”

How can i get this data into a pandas dataframe? i would like to avoid using Selenium.

Thanks!

Advertisement

Answer

I have no idea what you used to send request
but when I use module requests then problem makes + in query.

requests converts + to %2B but server needs +.

It needs to manually convert data using urllib.parse with safe="+"

JavaScript

Full working code:

In code you can see all needed headers to access server.

JavaScript

How I found +:

Python code was giving "Error getting base data: Error parsing xmlsquery" – so problem was in xmlsquery.

I copied working xmlsquery from request in browser using DevTool (tab: Network) in Chrome/Firefox
and compared (char-by-char) with response.request.body from Python code.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement