码迷,mamicode.com
首页 > 其他好文 > 详细

封装,调用函数,以及参数化

时间:2019-12-11 00:45:20      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:windows   submit   dir   log   use   ade   turn   com   agent   

#登录ecshop,新增地址,删除地址
import requests
import re
s=requests.session()
headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
def login(url,name,passwd):
data={
"username":name,
"password":passwd,
"act":"act_login",
"back_act":"./index.php"
}
a=s.post(url,data=data,headers=headers,verify=False)
print(‘登录code:%s‘%a.status_code)
return ‘登录code:%s‘%a.status_code
#print(dir(s))
def addaddr(addressee,address,tel):
addrdata={"country":1,"province":13,"city":135,"district":1475,
"consignee":addressee,"email":"8998@qq.com","address":address,
"tel":tel,"submit":"新增收货地址","act":"act_edit_address"}
ap=s.post(url,data=addrdata,headers=headers)
print(‘新增地址code:%s‘%ap.status_code)
return ‘新增地址code:%s‘%ap.status_code
def deladdr():
idhtml=s.get("http://localhost/ECshop_v3.6.0/ecshop/user.php?act=address_list")
id=re.findall(r"act=drop_consignee&id=(.+?)‘",idhtml.text)
idid=id[0]
#print(idid)
addrurl="http://localhost/ECshop_v3.6.0/ecshop/user.php?act=drop_consignee&id="+str(idid)
dd=s.get(addrurl,headers=headers)
print(‘删除地址code:%s‘%dd)
return dd.status_code

url=‘http://localhost/ECshop_v3.6.0/ecshop/user.php‘
names=‘fuhui‘
passwds=‘P@ssw0rd‘
login(url,names,passwds)
addaddr(‘angel‘,‘任汪勾小卖部‘,‘15527721040‘)
deladdr()

封装,调用函数,以及参数化

标签:windows   submit   dir   log   use   ade   turn   com   agent   

原文地址:https://www.cnblogs.com/canglongdao/p/12019740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!