正则
#正则表达式
import re
#re.match 匹配正则
line = 'hsh323243'
# 1.以 h 开头
math_res = re.match('h',line)
if math_res:
print('success')
else:
print('error')
# 2. 以h开头后面跟着一个字符
line = 'h21212444dd'
# . 可以匹配任意字符
math_res = re.match('h.',line)
if math_res:
print('success')
else:
print('error')
# 3. 以h开头后面跟着任意数量的数字
#\d 任意的0-9的数字, * 前面的那一个匹配的内容, 0-n次
line = 'hgscx3232323'
math_res = re.match('h\d*',line)
if math_res:
print('success')
else:
print('error')
# 4.以3结尾
# line = 'hdd3'
# # math_res = re.match('.*3$',line)
# # if math_res:
# # print('success')
# # else:
# # print('error')
# 5. 以h开头,以3结尾,中间只有一个字符串
# line = 'hd3'
# math_res = re.match('^h.3$',line)
# if math_res:
# print('success')
# else:
# print('error')
# 6. 以h开头,以3结尾,中间可以存在任意数量的字符串
line = 'hsss3'
math_res = re.match('^h.*3$',line)
if math_res:
print('success')
else:
print('error')
requests模块
#get请求
import requests
# url = 'http://www.baidu.com/'
# response = requests.get(url)
# 字符串
# print(response.text)
# 状态码
# print(response.status_code)
# print(response.url)
# byte
# print(response.content)
# print(response.headers)
r = requests.post('http://httpbin.org/post', data = {'key':'value'})
print(r.json())
print(r.encoding)
# r = requests.get('http://github.com', allow_redirects=False)
# print(r.status_code)
# # 重定向
# print(r.history)
#post请求
import requests,json
payload = {'key1': ('value1', 'value2')}
url = 'http://httpbin.org/post'
response = requests.post(url,data=json.dumps(payload))
print(response.text)
python 链接mysql
import pymysql
class Mysql_con(object):
def __init__(self):
self.db = pymysql.connect(host='127.0.0.1',user='root',password='123456',port='33060',database='py10')
self.cursor = self.db.cursor()
def execute_modify(self,sql):
self.cursor.execute(sql)
self.db.commit()
def __del__(self):
self.cursor.close()
self.db.cursor()
if __name__ == "__main__":
m = Mysql_con()
sql = 'insert into snow values (1)'
m.execute_modify(sql)