-1
import requests
req=requests.get(json_url)
with open('xxx','w') as f:

    f.write(req.text)
file_requests=req.json()

requests is a module, get is a function, so req=requests.get(), but what is req.txt and req.json(), is it also a function?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eric2009
  • 23
  • 4
  • `requests.get()` performs a get request to the specified URL, `req.text` is a property of the object returned by `requests.get` and `req.json()` is a builtin json decoder method of requests. – Vulpex Apr 06 '19 at 12:41
  • check out this docs [requests](http://docs.python-requests.org/en/master/user/quickstart/) – Justice_Lords Apr 06 '19 at 12:41
  • Welcome. You can see for `req.text` from [link](https://stackoverflow.com/questions/34819483/requests-explanation-of-the-text-format#34819497) and for req.json() from [link](http://docs.python-requests.org/en/latest/user/quickstart/#json-response-content) – Jacob Fuchs Apr 06 '19 at 12:42

1 Answers1

0

This line:

requests.get(json_url)

return python object(http://docs.python-requests.org/en/master/api/#requests.Response)

requests.Response:

  • has methods json (return http-body as json)
  • has attribute(text and content)

May be it is property, (read https://www.python.org/dev/peps/pep-0549/)

stovfl
  • 14,998
  • 7
  • 24
  • 51
ivan
  • 61
  • 3