案例 京東商城查詢

2021-10-06 14:43:39 字數 1842 閱讀 5779

#coding:utf-8

from pymysql import connect

class jd(object):

def __init__(self):

# 建立connection連線

self.conn = connect(host='localhost', port=3306, user='root', password='123456', database='scott', charset='utf8')

# 獲得cursor物件

self.cursor = self.conn.cursor()

def __del__(self):

# 關閉cursor物件

self.cursor.close()

self.conn.close()

def execute_sql(self, sql):

self.cursor.execute(sql)

for temp in self.cursor.fetchall():

print(temp)

def show_all_items(self):

# 顯示所有的商品

sql = 'select * from goods;'

self.execute_sql(sql)

def show_cates(self):

sql = 'select name from goods_cates;'

self.execute_sql(sql)

def show_brands(self):

sql = 'select name from goods_brands;'

self.execute_sql(sql)

def add_brands(self):

item_name = input('輸入新商品分類的名稱:')

sql = '''insert into goods_brands (name) values('%s')''' % item_name

self.cursor.execute(sql)

self.conn.commit()

print('商品名稱%s已錄入' % item_name)

@staticmethod

def print_memu():

print('----京東----')

print('1:所有的商品')

print('2:所有的商品分類')

print('3:所有的商品品牌分類')

return input('請輸入功能對應的序號:')

def run(self):

while true:

num = self.print_memu()

if num == '1':

# 查詢所有的商品

self.show_all_items()

elif num == '2':

# 查詢分類

self.show_cates()

elif num == '3':

# 查詢品牌分類

self.show_brands()

elif num == '4':

# 新增品牌分類

self.add_brands()

else:

print('輸入有誤,請重新輸入...')

def main():

# 1.建立乙個京東**物件

jd = jd()

# 2.呼叫這個物件的run方法,讓其執行

jd.run()

if __name__ == '__main__':

main()

案例 模擬京東快遞單號查詢

實現功能 當我們在文字框輸入內容時,文字框上面自動顯示大字型大小的內容 快遞單號輸入內容時,上面的大號字型盒子 con 顯示出來 這裡面的字型大小更大 表單檢測使用者輸入 給表單新增鍵盤事件 同時把快遞單號裡面的值 value 獲取過來賦值給con盒子 innertext 作為內容 如果快遞單號裡面...

京東商城登入邏輯分析,實現程式登入京東商城

做這件事的初衷是最近發現有京豆這東西,獲取京豆的方法之一就是每天登入,於是想寫乙個自動登入京東的程式,放入自啟動,每天自動登入。分析工具為foxfire加firebug,進入登入頁面new login.aspx,會從伺服器端返回帶有id uuid type hidden value a2c762bd...

JS案例 模擬京東快遞單號查詢

doctype html en utf 8 viewport content width device width,initial scale 1.0 x ua compatible content ie edge document title search con con before style...