As a salted fish University played 3 years of game just waking wake up, and now began to learn something, here to record their own learning.
Urllib Library before some understanding will not write, starting from the requests library (ˉ▽ ̄~).
The first thing to say is be sure to use the Official document: http://docs.python-requests.org/en/master/
Let's look at a column first:
Here are some basic uses of the requests library:
The specific code is just a little over the official documentation exercise, which is the most commonly used method.
The Response object contains all the information returned by the server and also contains the request information for the requests.
Property
Give the code for a standard crawl page:
1 ImportRequests2 3 defgeturl (URL):4 Try:5R=requests.get (url,timeout=100)6 r.raise_for_status ()7R.encoding=r.apparent_encoding#replacement Code Some Web page guessing code will error8 returnR.text9 except:Ten return "Exception" One A - if __name__=="__main__": -Url="http://jwweb.scujcc.cn/" the Print(Geturl (URL))
The code is given to our school's academic Web site if you do not r.apparent_encoding replacement r.enconding will report the encoding error you can try it.
First write this also no idea big guy light spray, content after a new understanding will also add in slowly improve also hope that we give some advice.
A path to the python reptile of salted fish (i): Requests Library