1、Dockerfile
FROM python:3.5
COPY . /var/
WORKDIR /var/
RUN pip install -r requirements.txt
CMD ["python", "./test.py"]
FROM python:3.5 鏡像源
COPY . /var/ 拷貝當(dāng)前目錄到鏡像系統(tǒng)/var 注意點(diǎn)代表當(dāng)前目錄
WORKDIR /var/ 切換鏡像目錄相當(dāng)于cd /var/
RUN pip install -r requirements.txt 運(yùn)行pip安裝包
CMD ["python", "./test.py"] 相當(dāng)于 python ./test.py
2、requirements.txt
requests
3、test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/6/20 10:04
# @Author : Py.qi
# @File : req_reqst.py
# @Software: PyCharm
from requests import request
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36'
}
response = request('GET', 'https://api.github.com/events',
headers=header) # 定義頭信息發(fā)送請(qǐng)求返回response對(duì)象
print(response.url) # 返回請(qǐng)求的URL
print(response.status_code) # 返回狀態(tài)碼200
print(response.encoding) # 返回編碼
print(response.text) # 返回響應(yīng)的內(nèi)容以u(píng)nicode表示
print(response.headers) # 返回頭信息
print(response.cookies) # 返回cookies CookieJar
print(response.json()) # 返回json數(shù)據(jù)