python入门常用方法(转json,模拟浏览器请求头,写入文件)

转json
import json
json = json.loads(html)

  

模拟浏览器请求头

import urllib.request


req = urllib.request.Request(url, data) req.add_header('User-Agent','Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36')

  

写入数据

file_object = open('content.txt', 'w')
file_object.write(content)
file_object.writelines(list_of_text_strings)  #写入多行
file_object.close()

  

文件夹

import os


folder = 'girlimage'
os.mkdir(folder) #创建目录
os.chdir(folder) #改变当前目录,到指定目录中。

  

python 字符串长度

python100例:http://www.iplaypy.com/python-100/

  

python100例:https://www.cnblogs.com/devin-guwz/p/5738676.html

https://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html

posted @ 2017-12-21 16:27  程序生(Codey)  阅读(618)  评论(0编辑  收藏  举报