This commit is contained in:
parent
7bf7f28d3d
commit
354ad41b6e
|
|
@ -1,16 +1,20 @@
|
|||
def server_id(): #服务器切换
|
||||
dev_ip='http://127.0.0.1' #本地环境
|
||||
sit_ip='https://www.baidu.com' #生产环境
|
||||
return sit_ip
|
||||
server_address = {
|
||||
'dev_ip' :'http://127.0.0.1',
|
||||
'sit_ip' :'https://www.baidu.com'}
|
||||
|
||||
return server_address['sit_ip']
|
||||
|
||||
#配置服务器数据库
|
||||
def n_sql():
|
||||
ip = '108.116.10.1'
|
||||
username = 'zhangsan'
|
||||
password = '773366w'
|
||||
port = '3306'
|
||||
charset ='UTF-8'
|
||||
# sql_config = {
|
||||
# ip = '108.116.10.1',
|
||||
# username = 'zhangsan',
|
||||
# password = '773366w',
|
||||
# port = '3306',
|
||||
# charset ='UTF-8',
|
||||
# }
|
||||
ip,username,password,port,charset = ['108.116.10.1','zhangsan','773366w','3306','UTF-8']
|
||||
return ip,username,password,port,charset
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
import os
|
||||
|
||||
|
||||
from ddt import ddt, data, unpack, file_data
|
||||
import unittest
|
||||
|
||||
|
||||
def get_data():
|
||||
testdata = [{'name': 'tom', 'age': 20}, {'name': 'kite', 'age': 30}]
|
||||
return testdata
|
||||
|
||||
|
||||
@ddt
|
||||
class MyTestCase(unittest.TestCase):
|
||||
# 读取元组数据-单组元素
|
||||
@data(1, 2, 3)
|
||||
def test1(self, value):
|
||||
print('读取元组数据-单组元素: ', value)
|
||||
|
||||
# 读取元组数据-多组元素
|
||||
@data((1, 2, 3), (4, 5, 6))
|
||||
def test2(self, value):
|
||||
print("读取元组数据-多组元素: ", value)
|
||||
|
||||
# 读取元组数据-拆分数据
|
||||
@data((1, 2, 3), (4, 5, 6))
|
||||
@unpack # 拆分数据
|
||||
def test3(self, value1, value2, value3):
|
||||
print("读取元组数据-拆分数据: ", value1, value2, value3)
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
import requests
|
||||
|
||||
|
||||
# url = 'https://search.51job.com/list/000000,000000,0000,00,9,99,%25E8%2587%25AA%25E5%258A%25A8%25E5%258C%2596%25E6%25B5%258B%25E8%25AF%2595%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=&type__1458=GqfxuDRDyAiQG%3DD8DlxGO4sX%2B4xR2AS2TD'
|
||||
# r_qcwy=requests.get(url = url,verify=false) #忽略证书verify
|
||||
# print(r_qcwy.text)
|
||||
#
|
||||
# #打印返回乱码设置
|
||||
# print(r_qcwy.encoding)
|
||||
#
|
||||
# #修改返回编码
|
||||
# r_qcwy.encoding ='gb2312'
|
||||
# print(r_qcwy.text)
|
||||
|
||||
|
||||
# url = 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2022-10-27&leftTicketDTO.from_station=BJP&leftTicketDTO.to_station=SHH&purpose_codes=ADULT'
|
||||
# r_12306 = url
|
||||
# headers = {'cookies':'_uab_collina=166685751566876959473097; JSESSIONID=72846201FDFECFF8B04E5EB10C4466AE; BIGipServerotn=1306067210.24610.0000; BIGipServerpassport=820510986.50215.0000; guidesStatus=off; highContrastMode=defaltMode; cursorStatus=off; RAIL_EXPIRATION=1667146521902; RAIL_DEVICEID=cTbOlQamiWIk7tg_0t24k6Jxmzs0vq7UhEAX5vCpy5YzvYu3x61t9-cHgBfrXjwg5SZpQ_HIII59DcsBjLvGbcDCEtKagv4qxbwryFt1_PnZjJixmJN1FH6pD897eJZw9IFmq4fPaqKtdfLUSJ2Mfnoce-A2bp3Y; fo=dhovpd2tutlmyxu5dzCjUcFaxO0ei8YX_35TudNO9J4BJ8cR6zMwAWBbZmr-pKys1JP1zBhVSf80FpMdlfsMl2ft40zavVq8poArrZIPitBg87HsG-KkhlwEtt11yTmVwyK-si_7pzaN_KQGNXdbklyQMkmvIdFlaoTnciEYt3D8HOzXQQbRRNNTrsI; route=6f50b51faa11b987e576cdb301e545c4; _jc_save_fromStation=%u5317%u4EAC%2CBJP; _jc_save_toStation=%u4E0A%u6D77%2CSHH; _jc_save_fromDate=2022-10-27; _jc_save_toDate=2022-10-27; _jc_save_wfdc_flag=dc'
|
||||
# }
|
||||
# r_12306 = requests.get(url = url,headers = headers)
|
||||
# print(r_12306.text)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import requests
|
||||
import re
|
||||
|
||||
url_51 = 'https://search.51job.com/list/000000,000000,0000,00,9,99,%25E8%2587%25AA%25E5%258A%25A8%25E5%258C%2596%25E6%25B5%258B%25E8%25AF%2595%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare='
|
||||
|
||||
r_51 = requests.get(url=url_51)
|
||||
r_51.encoding = 'gb2312'
|
||||
print(r_51.text)
|
||||
url_yun = re.findall('"company_href":"(.+?)","company_name":"艾德克斯电子(南京)有限公司"',r_51.text) #body中 text,html提取方式
|
||||
print(url_yun)
|
||||
|
||||
|
||||
r_51_yun=requests.get(url=url_yun[0])
|
||||
r_51_yun.encoding ='gb2312'
|
||||
print(r_51_yun.text)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import requests
|
||||
|
||||
#注册
|
||||
url = 'http://126.21.126.92/fanwen/m.php'
|
||||
date_regist = {
|
||||
'usertype' = 0,
|
||||
'username' = 'uds1111',
|
||||
'eamil' = '52545125@qq.com',
|
||||
|
||||
}
|
||||
r_regist = requests.post(url=url,date=date_regist)
|
||||
print(r_regist.content.decode('unicode_escape'))
|
||||
print(r_regist.cookies)
|
||||
|
||||
#获取注册cookies
|
||||
url_login = server_ip() + "/login"
|
||||
json_user= get_execl_row(4)[0]#读取配置文件、取第五行、第一个数据
|
||||
json = eval(json_user)
|
||||
r_a = requests.post(url=url,json=json_user,cookies=r_regist.cookies)
|
||||
print(r_a.encoding)
|
||||
print(r_a.encode('utf-8').decode('unicode_escape')) #把返回结果转为utf-8,解码为中文编码
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import requests
|
||||
from testcase.new_api_get_sql import get_sql
|
||||
r = rquests.session()
|
||||
|
||||
#抓取客户信息
|
||||
user_id = get_sql("select * from fanwe.user where user_name = 'admin'")[0][0]
|
||||
print(user_id,type(user_id)) #数据为元祖、
|
||||
url = 'http://126.21.126.92/fanwen/m.php'
|
||||
date = {
|
||||
'usertype'=0,
|
||||
'username'='uds1111,
|
||||
'eamil'='52545125@qq.com',
|
||||
'id'= user_id,
|
||||
}
|
||||
|
||||
rsult = r.post(url=url,date=date)
|
||||
print(r.text)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import openpyxl
|
||||
|
||||
|
||||
def read_excel(path):
|
||||
"""读取excel,工作簿——→工作表——→单元格"""
|
||||
# 获取工作簿
|
||||
workbook = openpyxl.load_workbook(path)
|
||||
# 获取工作表
|
||||
worksheet = workbook["Sheet1"]
|
||||
# 获取单元格数据(行和列均从1开始)
|
||||
data = worksheet.cell(1, 2).value
|
||||
# print(data)
|
||||
# 获取最大行
|
||||
rows = worksheet.max_row
|
||||
print(rows)
|
||||
# 获取最大列
|
||||
cols = worksheet.max_column
|
||||
print(cols)
|
||||
# 获取所有数据,并将数据用字典列表的形式储存[{'id':1,'username':"","passwd":''},{},{}]
|
||||
datas = []
|
||||
# 循环每一行的数据
|
||||
for row in range(2, rows + 1): # 从第二行开始取值
|
||||
data_dict = {}
|
||||
# 循环每一列的数据
|
||||
for col in range(1, cols + 1):
|
||||
key = worksheet.cell(1, col).value # 第一行的数据做为key
|
||||
value = worksheet.cell(row, col).value # 其余行的数据作为value
|
||||
data_dict[key] = value
|
||||
# print(data_dict)
|
||||
datas.append(data_dict)
|
||||
print(datas)
|
||||
Loading…
Reference in New Issue