批量写入数据
import urllib.request import re import ssl import threading import time as t from New_MyPython.Xlsx import CreateExcel ssl._create_default_https_context = ssl._create_unverified_context ''' 使用多线程写入UID ''' def save_uid(end): _uids_list = [] def threads(star,end): for i in range(star, end): _uids = [] url = 'https://www.oppo.cn/search-member?keyword=xxxx%s&page=1' % (0000+ i) req = urllib.request.urlopen(url) html = req.read().decode('utf-8') d = 'href="/member-(.*?)-1">' uid = re.findall(d, html) if '{' not in uid: user_name = 'xxxx%s' % str(0000 + i) _uids.append(uid[0]) _uids.append(user_name) print('第%s Append完成!' % i) _uids_list.append(_uids) start_time = t.time() thread1 = threading.Thread(target=threads, args=(1, int(end/2))) thread2 = threading.Thread(target=threads, args=(int(end/2), end)) thread1.start() thread2.start() thread1.join() thread2.join() stop_time = t.time() print('耗时:' + str(stop_time - start_time) + '秒') print('Uid List Save End!') return _uids_list uids_list = save_uid(400) file_ads = 'F:\\Community_Uids' sheet_name = 'UID' save_xlsx = CreateExcel.Create(file_ads, sheet_name) tatle = ['UID', 'USER_NAME'] save_xlsx.create_row(tatle) save_xlsx.create_column(uids_list)使用上一篇文章中的方法,保存测试数据