简体   繁体   中英

How to submit a javascript-form using Python requests library?

I want to get some price quotes from a bitcoin exchange called bitonic(.nl). On their frontpage they´ve got a little form on which you can fill in either an amount in Bitcoins or in Euros. If you fill in the bitcoin field the Euro-field gets updated, and if you enter an amount in Euros the Bitcoin-field gets updated (probably using javascript).

I now want to use the Python requests library to fill in the form and read out the resulting quote. I know how to request a page with requests ( r = requests.get('http://bitconic.nl') ), and I know you can do a similar thing using requests.post() . The problem is now that I don't know how to fill in this form and read out the result when the form is filled in using javascript.

Does anybody have any idea how I could do this? All tips are welcome!

I originally assumed that a simple form like this would not involve any HTTP request at all, and be done exclusively in (non-Ajax) Javascript. However, it does appear to make an HTTP request, so you can use requests to do the same thing.

response = requests.post('https://bitonic.nl/json/', data={'part': 'rate_convert', 'check': 'euros', 'euros': 46})
print response.json()

You can also download bitcoin quotes from here for free:

http://www.quandl.com/markets/bitcoin

The data is updated daily for several exchanges and different currencies, and is very "download" friendly. No registration needed if you need less than 50 requests per day.

Here is an API description on how to get the data:

http://www.quandl.com/help/api

Getting bitcoin quotes in csv is as easy as:

http://www.quandl.com/api/v1/datasets/BITCOIN/BTCDEEUR.csv

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM