分类 "Python" 下的文章

问题: okhttp的post传递参数如何写?

方法:

Post请示,传递json格式数据

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
     RequestBody body = RequestBody.create(JSON, json);
      Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
//同步
      Response response = client.newCall(request).execute();
    f (response.isSuccessful()) {
        return response.body().string();
    } else {
        throw new IOException("Unexpected code " + response);
    }
}

阅读全文

问题:python如何运行ffmpeg进程视频直播?

方法:

rtsp = '"%s"' % m.rtsp
rtmp = 'rtmp://192.168.1.12:1935/live/id%d' % m.id
cmd_str1 = 'ffmpeg -rtsp_transport tcp -i'
cmd_str2 = '-f flv -vcodec copy'
cmd = cmd_str1.split() + [rtsp] + cmd_str2.split() + [rtmp]
cmd_str = ' '.join(cmd)
# 不用shell不行
# p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
p = subprocess.Popen(cmd_str, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

阅读全文

问题:如何进行多进程抓取数据?

方法:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from multiprocessing import Pool
import requests
from time import sleep

fin = open('pass_list.txt', 'r', encoding='UTF-8', errors='ignore')
host = 'http://xxx.com/'

阅读全文

问题:ubuntu下如何进行doc转pdf?

解决: 使用libreoffice

libreoffice --headless --convert-to pdf /home/qc/a.docx --outdir /home/qc

方法:
下面是一个脚本

阅读全文

问题:python如何获取两个日期之间的月份列表

方法:

from datetime import datetime

#这是起始时间,假设某位博主是2018年10月6日注册的
start=datetime(2018,10,6)
#这是结束时间,也就是当前的时间
end=datetime.now()
#计算起止日期之间有多少个月(月份的差值)
month_num=12*(end.year-start.year)+end.month-start.month
#这个空列表用于存储我们最终得出的所有的年月
time_list=[]
#年份的起点是注册日期的年份
year=start.year
#月份的起点是注册日期的月份
month=start.month

阅读全文