Mocha Night

一生漂泊,四海为家,哪里都是家乡,哪里都是异乡...


  • Home

  • Archives

禁用安全警告

Posted on 2018-03-14

requests中如果启用了verify=False 会出现大量的证书错误警告

from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

re中指定前后文中间的字符串:

response = re.findall('(?:前文字)(.+)(?:后文字)',response.text)

python中request获取数据保存到文件

Posted on 2018-01-07

例子如下

aaa = json.loads(response.text)
if aaa['data']['Word8'] != []:
    #print(num)
    txt = aaa['data']['Word8']
    #print(txt)
    # open
    f = open('word8.txt','a+')
    f.write(str(txt)+"\n")
    f.close()
if aaa['data']['Word2'] != []:
    txt2 = aaa['data']['Word2']
    f = open('word2.txt','a+')
    f.write(str(txt2)+"\n")
    f.close()

python中非标准json处理

Posted on 2017-12-18

python中使用requests库时如果服务器返回结果非标准json格式,可以用re来处理,只匹配出标准的json格式。
例子如下

response = requests.get('https://lay.com/', headers=headers, params=params, cookies=cookies, verify=False)
js = json.loads(re.findall(r'\{.+\}', response.text)[0])
tk = js['data']['Token']

python编码问题

Posted on 2017-12-17

requests下返回结果为unicode编码,需要转换为中文可以如下命令:

response = requests.post('https://xxx.com/', headers=headers, params=params, cookies=cookies, data=data, verify=False)
response1 = response.text
new=response1.encode('latin-1').decode('unicode_escape')
print(new)

如果返回结果为url编码,需要转换为中文为如下

print(urllib.request.unquote(response.text))

hexo 主题安装

Posted on 2017-12-16

这里以next主题为例

git clone https://github.com/iissnan/hexo-theme-next themes/next

安装完毕以后修改_config.yml文件theme为next,保存。

进行本地测试:

hexo s --debug

没问题推送代码平台

hexo clean && hexo g && hexo d
sudo  hexo generate --deploy

关于

Posted on 2017-12-16

托管于coding,由hexo驱动。

这里备忘一下hexo的一些命令:

安装了hexo-myadmin插件,可在本机进行可视化编辑。

hexo server -d

即可在4000端口/admin/下维护.

维护完hexo后推送到coding.

hexo clean && hexo g && hexo d
sudo  hexo generate --deploy

Mocha

6 posts
5 tags
© 2020 Mocha
Powered by Hexo
|
Theme — NexT.Mist v5.1.4