python api call interface to obtain data, how to call api python interface (with code)

Use Python3 implement HTTP get method. Use data aggregation application programming interface, you can call the little cat hair AI writing API. This is a free application programming interface, the first on the code, details written on the back:

Requests Import 
Import Time 
Import Re 
SE = requests.session () 

IF __name__ == '__main__': 
    POST_URL = "http://api-ok.xiaofamao.com/api.php?json=0&v=1&key=xxxxxx" # own try to get Key 
    post_data = { 
        'wenzhang': 'Moonlight, suspected ground frost. ' 
    } 
    The Text = se.post (POST_URL, Data = post_data) .text.replace ( "'", ' "') .replace ( '/', '/') 
    Print (the Text)

 

First, what is the API? The full name is also known as application programming interface application programming interface. It is referred to as the application programming interface. When I first contacted interface calls, I do not know what to write, because I read the entire project. This project is written by a tornado. After the tornado looked a long time, I found myself in the wrong direction. I'm just looking directly at the interface, because no one told me the whole process of the project. I had to force myself to look at it. I have to do is find the main entrance to the program, and then call it step by step according to function.
When I write an interface, because I have to write with background and browser access, each access only need to pass the appropriate parameters to call the appropriate interface. Interface can be written by others, it may also be provided by partner companies. Of course, the cooperation provided by the company is not free. Now basically, if I did not visit it once, it only charges a few cents. When you hear this, do not underestimate it a bit. Sometimes if you hit a few million phones, you will spend a lot of money. Some people think we can not do monthly payments? sorry, I do not know. In short, we calculated one by one, because for the first time, I think I bought those directly bought all the data we want to store them in a local database, when I use them directly from my own database they transferred. Later, I found that I think too much, pseudo-original API .
The interface library called by the request to access the python, which is basically a request to get or post. Some of the interface is encrypted, then we must provide the other party to use our public key to encrypt or decrypt, and then use the appropriate parameter access. We want the data returned is basically the result of the request in order to resolve json format. Therefore, after the request, we can provide json function with a request to resolve it, and then extract the data to a data access time.
Yes, the interface is so simple to call, but with the preparation of background, I found the request library is now more powerful, as long as it is http or https, I'm glad I read the request and bs4 in a week, I really do not play telephone engineers to reptiles, reptiles time if I do not study the request, you can write 4 = dead scrapy to write it anyway? Urllib word basically been deleted. If you have a requirement, why should this?

Guess you like

Origin www.cnblogs.com/phploser/p/12624058.html