av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Python中Cookies導(dǎo)出某站用戶數(shù)據(jù)的方法

瀏覽:4日期:2022-06-19 16:14:55

應(yīng)朋友需要,想將某客戶的數(shù)據(jù)從某站里導(dǎo)出,先去某站搞個賬號,建幾條數(shù)據(jù)觀察一番,心里有底后開搞。

1.Python環(huán)境搭建

之前電腦有安裝過PyCharm Community 2019.1,具體安裝過程就不寫了,先跑個HelloWorld,輸出正常后正式開整。

2.利用抓包工具或者Google瀏覽器調(diào)試模式拿到請求參數(shù)

Cookies參數(shù)如下:

cookies = {’JSESSIONID’: ’XXX’, ’phone’: ’XXX’,’password’: ’XXX’,’isAuto’: ’0’, ’ loginAccess’: ’XXX’}

headers請求頭信息構(gòu)造:

headers = { ’Connection’: ’keep-alive’, ’sec-ch-ua’: ’'Google Chrome';v='89', 'Chromium';v='89', ';Not A Brand';v='99'’, ’Accept’: ’application/json, text/javascript, */*; q=0.01’, ’X-Requested-With’: ’XMLHttpRequest’, ’sec-ch-ua-mobile’: ’?0’, ’User-Agent’: ’Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36’, ’Content-Type’: ’application/json’, ’Sec-Fetch-Site’: ’same-origin’, ’Sec-Fetch-Mode’: ’cors’, ’Sec-Fetch-Dest’: ’empty’, ’Referer’: ’https://xxx.xxx.xxx’, ’Accept-Language’: ’zh-CN,zh;q=0.9’,}

請求路徑:

params = ( (’method’, ’getGoodsList’))

請求參數(shù)組裝:

data = ’{'pageSize':1000,'pageNumber':1,'searchText':'','sortOrder':'asc','isAdvancedSearch':false}’

pageSize:每頁數(shù)據(jù)數(shù)量pageNumber:頁碼searchText:搜索條件sortOrder:排序

3.利用Requests模擬請求并獲取數(shù)據(jù)

response = requests.post( ’https://xxx.xxx.xxx’, headers=headers, params=params, cookies=cookies, data=data)print(response.text.encode(’utf8’))res = json.loads(response.text)4.創(chuàng)建Excel表格

t = time.time()randStr = int(round(t * 1000))tSheetName = 'a_' + str(randStr) + '.xlsx'workbook = xlsxwriter.Workbook(tSheetName)worksheet = workbook.add_worksheet()5.表頭及數(shù)據(jù)組裝

cursor = 0picurl = ’’writeExcel(row=cursor)for obj in res['rows']:cursor += 1picurl = ’’ if obj[’ImageKID’]:picurl = ’https://xxx.xxx.xxx? imageKid=’+obj[’ImageKID’]writeExcel(row=cursor,Description=obj[’Description’], Category=obj[’Category’], Series=obj[’Series’],BaseUnit=obj[’BaseUnit’],Qty=obj[’Qty’], CostPrice=obj[’CostPrice’],SalePrice=obj[’SalePrice’], RetailPrice=obj[’RetailPrice’],Barcode=obj[’Barcode’], Remark=obj[’Remark’], ImageKID=picurl)6.將數(shù)據(jù)寫入Excel表格中

def writeExcel(row=0, Description=’’, Category=’’, Series=’’, BaseUnit=’’, Qty=’’, CostPrice=’’, SalePrice=’’, RetailPrice=’’, Barcode=’’, Remark=’’,ImageKID=’’): if row == 0:worksheet.write(row, 0, ’名稱’)worksheet.write(row, 1, ’貨號’)worksheet.write(row, 2, ’規(guī)格’)worksheet.write(row, 3, ’單位’)worksheet.write(row, 4, ’庫存’)worksheet.write(row, 5, ’成本’)worksheet.write(row, 6, ’批發(fā)價’)worksheet.write(row, 7, ’零售價’) worksheet.write(row, 8, ’條碼’)worksheet.write(row, 9, ’備注’)worksheet.write(row, 10, ’圖片’)else: if ImageKID!=’’: image_data = io.BytesIO(urllib.urlopen(ImageKID).read()) worksheet.insert_image(row, 10, ImageKID, {’image_data’: image_data})worksheet.write(row, 0, Description)worksheet.write(row, 1, Category)worksheet.write(row, 2, Series) worksheet.write(row, 3, BaseUnit)worksheet.write(row, 4, Qty)worksheet.write(row, 5, CostPrice) worksheet.write(row, 6, SalePrice) worksheet.write(row, 7, RetailPrice) worksheet.write(row, 8, Barcode)worksheet.write(row, 9, Remark)worksheet.set_column(10, 10, 23)worksheet.set_row(row, 150)

注意圖片路徑不存在的情況,否則會執(zhí)行異常

write方法:

def write(self, row, col, *args):'''Write data to a worksheet cell by calling the appropriate write_*()method based on the type of data being passed.Args: row: The cell row (zero indexed). col: The cell column (zero indexed). *args: Args to pass to sub functions.Returns: 0: Success. -1: Row or column is out of worksheet bounds. other: Return value of called method.'''return self._write(row, col, *args)

通過set_row方法設(shè)置表格行高

def set_row(self, row, height=None, cell_format=None, options=None):'''Set the width, and other properties of a row.Args: row: Row number (zero-indexed). height: Row height. (optional). cell_format: Row cell_format. (optional). options: Dict of options such as hidden, level and collapsed.Returns: 0: Success. -1: Row number is out of worksheet bounds.......'''

通過set_column方法設(shè)置圖片列寬度:

def set_column(self, first_col, last_col, width=None, cell_format=None, options=None):'''Set the width, and other properties of a single column or arange of columns.Args: first_col: First column (zero-indexed). last_col: Last column (zero-indexed). Can be same as first_col. width: Column width. (optional). cell_format: Column cell_format. (optional). options: Dict of options such as hidden and level.Returns: 0: Success. -1: Column number is out of worksheet bounds. ......'''

通過insert_image插入網(wǎng)絡(luò)圖片:

def insert_image(self, row, col, filename, options=None):'''Insert an image with its top-left corner in a worksheet cell.Args: row: The cell row (zero indexed). col: The cell column (zero indexed). filename: Path and filename for image in PNG, JPG or BMP format. options: Position, scale, url and data stream of the image.Returns: 0: Success. -1: Row or column is out of worksheet bounds.'''# Check insert (row, col) without storing.if self._check_dimensions(row, col, True, True): warn(’Cannot insert image at (%d, %d).’ % (row, col)) return -1if options is None: options = {}x_offset = options.get(’x_offset’, 0)y_offset = options.get(’y_offset’, 0)x_scale = options.get(’x_scale’, 1)y_scale = options.get(’y_scale’, 1)url = options.get(’url’, None)tip = options.get(’tip’, None)anchor = options.get(’object_position’, 2)image_data = options.get(’image_data’, None)description = options.get(’description’, None)decorative = options.get(’decorative’, False)# For backward compatibility with older parameter name.anchor = options.get(’positioning’, anchor)if not image_data and not os.path.exists(filename): warn('Image file ’%s’ not found.' % force_unicode(filename)) return -1self.images.append([row, col, filename, x_offset, y_offset, x_scale, y_scale, url, tip, anchor, image_data, description, decorative])return 0

注意insert_image(row, colunmNum, ‘xx.png’, {‘url’: xxx})并不能插入網(wǎng)絡(luò)圖片,只是給本地圖片一個url路徑

7.關(guān)閉表格

workbook.close()8.附引入的包

# -*- coding: UTF-8 -*-# 批量獲取XX數(shù)據(jù)import ioimport json import requestsimport sysimport xlsxwriterimport timeimport urllib9.代碼跑起來

Python中Cookies導(dǎo)出某站用戶數(shù)據(jù)的方法

在看下Excel表格中導(dǎo)出的信息

Python中Cookies導(dǎo)出某站用戶數(shù)據(jù)的方法

到此這篇關(guān)于Python中Cookies導(dǎo)出某站用戶數(shù)據(jù)的方法的文章就介紹到這了,更多相關(guān)Python Cookies導(dǎo)出數(shù)據(jù)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 日本亚洲一区 | 91精品国产一区二区 | 国产精品欧美精品 | 一区精品在线观看 | 国产自产c区 | 久久综合狠狠综合久久综合88 | 亚洲欧美成人在线 | 日韩中文字幕在线播放 | 欧美日韩最新 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 国产精品久久久久久久久久久久久久 | 青青久久| 日日日日操 | 91久久北条麻妃一区二区三区 | h片在线免费看 | 国产精品欧美日韩 | 欧美区在线观看 | av在线免费观看网址 | 日韩美女一区二区三区在线观看 | 国产亚洲成av人片在线观看桃 | 亚洲91精品 | 亚洲天堂中文字幕 | 欧美日韩精品久久久免费观看 | 中文字幕日本一区二区 | 美日韩免费视频 | 免费在线观看av的网站 | av入口| 精品欧美一区二区精品久久久 | 在线观看中文字幕av | 成人av电影在线 | 国产精品乱码一区二区三区 | 国产一区二区久久 | 欧美黑人一区二区三区 | 欧美激情五月 | 奇米超碰 | 日韩免费视频一区二区 | 99亚洲精品 | 天堂男人av| 国偷自产av一区二区三区 | 1级黄色大片 | 亚洲国产成人精品女人久久久野战 |