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


    #登录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()
    越努力,越幸运!!! good good study,day day up!!!
  • 相关阅读:
    LDA-math-MCMC 和 Gibbs Sampling
    本地blast详解
    【shell命令】拆分、合并、排序、比较文件
    数学中竟然还有这样的定理!
    数学之美番外篇:平凡而又神奇的贝叶斯方法
    glean工具和maker工具
    Perl语言中的ig
    批量替换某个目录下所有文件里的内容
    RepeatMasker使用
    Hi-C文库制备的连接酶连接效果
  • 原文地址:https://www.cnblogs.com/canglongdao/p/12019740.html
Copyright © 2020-2023  润新知