Download and install
python-3.6.4-amd64.exe
pycharm-community-2017.3.2.exe
If you want to install the extension package:
command line example (install urllib3):
pip install requests
pycharm installation as shown:
2: Download File programming example
#download.py import urllib.request def downloadFile(name): url="http://www.zjport.gov.cn/themes/gaza/images/index/"+name filename="f:/temp/"+name urllib.request.urlretrieve(url, filename) downloadFile("1.png")
Run two problems:
1. urllib.error.HTTPError: HTTP Error 404: Not Found
The file is not found, or it is prohibited by the anti-crawler policy
2. The permission denied
file directory is restricted
3 : Access the http interface programming example
#httprequest.py #extension pack import requests import json #download.py import download def getFileByRequests(): r = requests.get('http://192.168.3.144/data/getFile') if r.status_code==200: #'[{"filename":"1.zip"},{"filename":"2.zip"}]' return r.text else: return '' #parse json while(True): files = getFileByRequests() arr=json.loads(files) for i in range(0, len(arr)): print(arr[i].get('filename')) download.downloadFile(arr[i].get('filename'))
It can be debugged and run in pycharm.
Four: The script runs
cd c:\users\zhenggm\pycharmprojects\untitled
python httprequest.py