def Excel(): for filename in os.listdir('.'): if(filename.endswith('lts.txt')): page=0 f_d=open(filename,'r') f_ex=xlwt3.Workbook(encoding='utf-8') sheet=f_ex.add_sheet('sheet') count=0 for line in f_d.readlines(): lists=line.split('||') try: num=0 for text in lists: sheet.write(count,num,text) num+=1 count+=1 except: f_ex.save(str(page)+'.xls') page+=1 f_ex=xlwt3.Workbook(encoding='utf-8') sheet=f_ex.add_sheet('sheet') count=0 num=0 for text in lists: sheet.write(count,num,text) num+=1 count+=1 f_ex.save(str(page)+'.xls')
def main(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') count = 0 startpage = 1 keys = [ 'date', 'name', 'industry', 'local', 'round', 'capital', 'Investmenters' ] while startpage < 1143: try: results = get_infor('https://www.itjuzi.com/investevents?page=%s' % startpage) except: time.sleep(5) continue for item in results: num = 0 for key in keys: sheet.write(count, num, item[key]) num += 1 count += 1 print(startpage, '--ok') startpage += 1 time.sleep(3) excel.save('investevents.xls')
def writexls(file_name,table_name,data_list): book=xlwt.Workbook() sheet=book.add_sheet(table_name) row=0 url="http://www.baidu.com" for datarow in data_list: col=0 for data in datarow: #sheet.row(row).write(col,data) if col==1 and len(datarow[15])<255 and row>0: sheet.write(row, col, Formula('HYPERLINK("%s"; "%s")'%(datarow[15],data)),h_style) elif col==15: col+=1 else: sheet.write(row, col, data) #print(data) col+=1 row+=1 book.save(file_name)
def excel(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') count = 0 labels = [ 'postiontype', 'company', 'salary', 'workYear', 'education', 'industryField', 'companySize', 'city', 'financeStage' ] page = 1 while page < 300: try: jobs = get_job('', page) except: time.sleep(5) continue for job in jobs: num = 0 for i in labels: sheet.write(count, num, job[i]) num += 1 count += 1 print(page, count) page += 1 time.sleep(2) excel.save('jobs.xls')
def combine_xls(): all_lines = [] xls_files = glob('./' + '*.xls') for file_name in xls_files: if '_pages' in file_name: info = xlrd.open_workbook(file_name) content = info.sheets()[0] nrows = content.nrows ncols = content.ncols for i in range(1, nrows): row_lst = [] for j in range(0, ncols - 1): row_lst.append(str(content.cell(i, j).value)) all_lines.append([row_lst[0].split('_')[0]] + row_lst[2:]) wb = xlwt3.Workbook() sheet = wb.add_sheet("计算机类图书信息") for i in range(0, len(all_lines)): for j in range(0, len(all_lines[i])): sheet.write(i, j, all_lines[i][j]) #wb.save("图书信息_04_16.xls") wb.save("计算机类图书信息" + ".xls")
def work(self): self.f = xlwt3.Workbook() self.sheet = self.f.add_sheet('sheet') self.count = 0 for page in range(338): get_url = get_urls( 'http://shanghai.anjuke.com/community/W0QQp1Z7QQp' + 'Z' + str(page + 1)) print(page) urls = get_url.run() for url in urls: item = get_infor(url) item.work() if item.statue == 0: continue self.sheet.write(self.count, 0, '浦东') num = 1 for infor in item.infortable: self.sheet.write(self.count, num, infor) num += 1 self.sheet.write(self.count, num, item.price) num += 1 self.sheet.write(self.count, num, url) self.count += 1 self.f.save('data.xls')
def main(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') keys = [ 'summary', 'temperature', 'windSpeed', 'humidity', 'visibility', 'pressure' ] count = 0 starttime = 1262318400 endtime = time.time() session = requests.session() while starttime < endtime: result = getdata(starttime, session) try: data = result[10] except: continue date = timetostr(starttime) num = 1 for key in keys: try: sheet.write(count, num, data[key]) num += 1 except: num += 1 continue sheet.write(count, 0, date) starttime += 86400 count += 1 print(date, '--ok') excel.save('result.xls')
def work(self): self.f=xlwt3.Workbook() self.sheet=self.f.add_sheet('sheet') self.count=0 for page in range(50): get_url=get_urls('http://www.dianping.com/search/category/1/20/g187r12'+'p'+str(page+1)) print(page) urls=get_url.run() for url in urls: try: item=get_infor(url) item.work() except: continue if item.statue==0: continue self.sheet.write(self.count,0,'购物') self.sheet.write(self.count,1,'超市便利店') self.sheet.write(self.count,2,'闵行') self.sheet.write(self.count,3,item.area) self.sheet.write(self.count,4,item.title) self.sheet.write(self.count,5,item.address) self.sheet.write(self.count,6,item.tel) self.sheet.write(self.count,7,item.price) self.sheet.write(self.count,8,item.times) self.sheet.write(self.count,9,url) self.count+=1 self.f.save('data.xls')
def excel(): f = open('data.txt', 'r') ex = xlwt3.Workbook() sheet = ex.add_sheet('sheet') count = 0 rels = [ '品牌等级:(.*?)\|\|', '关注指数:(.*?)\|\|', '\|\|.*?董事.*?:(.*?)品牌创立', '时间:(.*?)\|\|', '发源地:(.*?)\|\|', '官方网站:(.*?)\|\|', '客服电话:(.*?)\|\|', '告词:(.*?)\|\|', '(产品\d+)]', '(网点\d+)]', '(新闻\d+)]', '(网店.*?)]' ] for line in f.readlines(): line = line.replace('\n', '').replace('信用指数:', '') lists = [] for rel in rels: try: i = re.findall(rel, line)[0] except: i = '--' lists.append(i) strs = line.split('||') sheet.write(count, 0, strs[0]) sheet.write(count, 1, strs[1]) sheet.write(count, 2, strs[2]) sheet.write(count, 3, strs[3]) sheet.write(count, 4, strs[4]) sheet.write(count, 5, strs[5]) num = 6 for i in lists: sheet.write(count, num, i) num += 1 sheet.write(count, num, strs[-1]) count += 1 ex.save('data.xls')
def main(): data = xlrd.open_workbook('data/data.xlsx') table = data.sheets()[0] excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') for row in range(table.nrows): print(row) fromport = table.cell(row, 0).value toport = table.cell(row, 1).value commodityName = table.cell(row, 2).value Load_Type = table.cell(row, 3).value fromid = get_port(fromport) toid = get_port(toport) if fromid == False or toid == False: sheet.write(row, 0, fromport) sheet.write(row, 1, toport) sheet.write(row, 2, commodityName) sheet.write(row, 3, Load_Type) sheet.write(row, 4, '') excel.save('data/result.xls') continue try: result = get_infor( fromid, toid, commodityName.replace('&', '%26').replace(' ', '+').replace(',', '%2C')) except: result = '' sheet.write(row, 0, fromport) sheet.write(row, 1, toport) sheet.write(row, 2, commodityName) sheet.write(row, 3, Load_Type) sheet.write(row, 4, result) excel.save('data/result.xls')
def main(username, passwd, page): excel = xlwt3.Workbook() count = 0 sheet = excel.add_sheet('sheet') session = login(username, passwd) for pagenum in range(int(page)): ships = get_urls(session, pagenum + 1) for ship in ships: try: ship = infor(session, ship) except: continue if ship['img'] == False: ship['phone'] = '' continue with open('temp.png', 'wb') as img: img.write(ship['img']) phonenum = img_ocr('temp.png') ship['phone'] = phonenum for ship in ships: try: sheet.write(count, 0, ship['title']) sheet.write(count, 1, ship['weight']) sheet.write(count, 2, ship['date']) sheet.write(count, 3, ship['from']) sheet.write(count, 4, ship['to']) sheet.write(count, 5, ship['phone']) count += 1 except: continue print(pagenum + 1, '---ok') excel.save('data.xls')
def run(self): try: os.mkdir('data') except: print('..') for key in self.urls: try: html=requests.get(self.urls[key],headers=self.headers).text except: continue table=BeautifulSoup(html,'html.parser').find('table',attrs={'class':'today'}).find_all('tr') self.f=xlwt3.Workbook() self.sheet=self.f.add_sheet('sheet') self.count=0 for item in table: try: infor=item.find_all('td') self.sheet.write(self.count,0,infor[0].get_text()) num=1 for i in infor[2].find_all('em'): self.sheet.write(self.count,num,i.get_text()) num+=1 self.count+=1 except: continue self.f.save('data/'+key+'.xls')
def main(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') count = 0 keys = [ 'title', 'commentsNumber', 'asin', 'date', 'Rank', 'feature', 'Des' ] browser = webdriver.Firefox() browser.get('http://www.amazon.co.uk') input('在浏览器中输入店铺链接,待加载完成后确认') browser.implicitly_wait(10) results = get_products(browser) for url in results: browser.get(url) time.sleep(5) try: infor = inforParser(browser.page_source) except: continue num = 0 for key in keys: sheet.write(count, num, infor[key]) num += 1 print(count) count += 1 excel.save('data.xls')
def __init__(self): self.session = requests.session() self.headers = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive' } self.f = xlwt3.Workbook() self.sheet = self.f.add_sheet('sheet') self.lists = [ 'id', 'Loan_Title', 'Loan_type', 'Loan_Status', 'Amount', 'Interest_Rate', 'Term', 'Next_Payment_Day', 'Term_Remain', 'Repayment_Type', 'Des', 'Guarantee_Type', 'Early_Repayment_Rate', 'Borrower_Id', 'Userid', 'Age', 'Education', 'Marital status', 'Working_City', 'Company_Scale', 'Position', 'Employment_Sector', 'Emploment_Length', 'Homeowner', 'Mortgage', 'Car', 'Car_Loan', 'Total_Amount', 'Number_of_Succesful_Loan', 'Income_Range_Monthly', 'Number_of_Borrow', 'Number_of_Repaid', 'Outstanding', 'Overdue_amount', 'Severe_overdue', 'Credit_Score', 'Number_Arrears', 'Credit_Limit' ] self.count = 1 num = 0 self.login() self.text_f = open('text.txt', 'a') self.failed_f = open('failed.txt', 'a')
def create_excel_book(self, bookname, list_sql): wb = xlwt3.Workbook(style_compression=2) for counter, sql in enumerate(list_sql): self.add_sheet_excel(sql[1], wb, sql[0]) report_folder = os.getcwd() + '\\reports\\' if not os.path.exists(report_folder): os.makedirs(report_folder) wb.save(report_folder + bookname + '_{0}__{1}.xls'.format(self.date_start, self.date_end))
def test_create_mini_xls(self): book = xlwt3.Workbook() sheet = book.add_sheet('xlwt was here') book.save('mini.xls') self.assertTrue( filecmp.cmp(from_tst_dir('mini.xls'), from_tst_dir(os.path.join('output-0.7.2', 'mini.xls')), shallow=False))
def __init__(self): self.session=requests.session() self.headers = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'keep-alive'} self.f=xlwt3.Workbook() self.sheet=self.f.add_sheet('sheet') self.count=0
def run(): name = '相机' f = xlwt3.Workbook(encoding='utf-8') sheet = f.add_sheet('sheet') data = xlrd.open_workbook(name + '.xls') table = data.sheets()[0] for i in range(table.nrows): line = table.cell(i, 0).value line = fan_jian(line) sheet.write(i, 0, line) f.save(name + '_.xls')
def __init__(self): self.f = xlwt3.Workbook(encoding='utf-8') self.sheet = self.f.add_sheet('sheet', cell_overwrite_ok=True) self.sheet1 = self.f.add_sheet('sheet1', cell_overwrite_ok=True) self.count = 1 head = ['公司', '职位', '职位发布城市', '工作经验', '学历要求', '年龄要求', '薪水'] num = 0 for i in head: self.sheet.write(0, num, i) self.sheet1.write(0, num, i) num += 1 self.f.save('data.xls')
def insert_value(path): workbook_new = xlwt3.Workbook() #创建一个Excel对象 sheet_new = workbook_new.add_sheet('create_new_sheet', cell_overwrite_ok=True) sheet_new.write(0, 0, "name") sheet_new.write(0, 1, "sex") for i in range(1, 101): name = create_value('abcdefg', 3) sex = create_value('01', 1) sheet_new.write(i, 0, name) sheet_new.write(i, 1, sex) workbook_new.save(path)
def write_txt_to_xls(txt_file): with open(txt_file, 'rb') as f: file_content = f.read().decode('utf-8') file_json = json.loads(file_content) xls_content = xlwt3.Workbook() sheet = xls_content.add_sheet('numbers') for i in range(len(file_json)): data = file_json[i] for j in range(len(data)): sheet.write(i, j, data[j]) xls_content.save('numbers.xls')
def write_txt_to_xls(txt_file): # Read form the txt file txt_object = open(txt_file, 'r') file_content = json.load(txt_object) # Write to the xls file xls_object = xlwt3.Workbook() sheet = xls_object.add_sheet('city') for i in range(len(file_content)): sheet.write(i, 0, i + 1) data = file_content[str(i + 1)] sheet.write(i, 1, data) xls_object.save('city.xls')
def writexls(file_name, table_name, data_list): book = xlwt.Workbook() sheet = book.add_sheet(table_name) row = 0 for datarow in data_list: col = 0 for data in datarow: sheet.row(row).write(col, data) col = col + 1 row = row + 1 book.save(file_name)
def write_txt_to_xls(txt_file): # Read form the txt file txt_object = open(txt_file, 'r') file_content = json.load(txt_object) # Write to the xls file xls_object = xlwt3.Workbook() sheet = xls_object.add_sheet('numbers') for i in range(len(file_content)): data = file_content[i] for j in range(len(data)): sheet.write(i, j, data[j]) xls_object.save('numbers.xls')
def save_fixed_original(self): """ Method that prepares fixed original table to be saved into new file as xlwt table and then calls save_file to actually save the table. """ wb = xlwt.Workbook() ws = wb.add_sheet('Page1') for i in range(len(self.codes)): ws.write(i, 0, self.codes[i]) ws.write(i, 1, self.est[i]) ws.write(i, 2, self.eng[i]) ws.write(i, 3, self.rus[i]) self.save_file(wb, original=True)
def write_txt_to_xls(txt_file): with open(txt_file, 'rb') as f: file_content = f.read().decode('utf-8') file_json = json.loads(file_content) xls_object = xlwt3.Workbook() sheet = xls_object.add_sheet('student') for i in range(len(file_json)): sheet.write(i, 0, i + 1) data = file_json[str(i + 1)] for j in range(len(data)): sheet.write(i, j + 1, data[j]) xls_object.save('student.xls')
def Excel(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') count = 0 for line in open('data.txt', 'r').readlines(): line = line.replace(',||', '||').replace('||', ' ||').replace('\n', '') lists = line.split('||') num = 0 for i in lists: sheet.write(count, num, i) num += 1 count += 1 excel.save('data.xls')
def main(): pageurls=['http://invest.ppdai.com/loan/list_safe_s0_ppage?Rate=0','http://invest.ppdai.com/loan/list_riskmiddle_s0_ppage?Rate=0','http://invest.ppdai.com/loan/list_riskhigh_s0_ppage?Rate=0'] labels=['新手收益区','中风险收益区','高风险收益区'] excel=xlwt3.Workbook() for index in range(len(pageurls)): sheet=excel.add_sheet(labels[index]) count=0 pageurl=pageurls[index] for page in range(1,100): try: urls=geturls(pageurl.replace('page',str(page))) except: break for url in urls: try: loan=loaninfor(url.split('|')[-1]) except: continue result=[] result.append(url.split('|')[0]) lists=loan.split('|') result.append(lists[1]) result.append(lists[3].replace('借入信用:','')) result.append(lists[5].replace('借款金额:','')) result.append(lists[6].replace('年利率:','')) result.append(lists[7].replace('期限:','')) result.append(lists[8].replace('进度条:','')) history=eval(lists[-1]) if history==[]: continue sum=0 for index_hi in range(len(history)-1): try: sum+=calculate_time(history[index_hi].split('-')[1],history[index_hi+1].split('-')[1]) except: continue try: diff=sum/(len(history)-1) except: continue for item in history: num=0 for i in result: sheet.write(count,num,i) num+=1 sheet.write(count,num,item.split('-')[0]) sheet.write(count,num+1,item.split('-')[1]) sheet.write(count,num+2,diff) count+=1 excel.save('result.xls') print(labels[index],'--',page,'--ok')
def main(): excel = xlwt3.Workbook() sheet = excel.add_sheet('sheet') queue = [] urls = ['http://news.fudan.edu.cn'] exists_urls = [] count = 0 try: os.mkdir('fudan') except: print('Exists') while len(urls): url = urls.pop() if url in exists_urls: continue exists_urls.append(url) work = Infor(url) queue.append(work) if len(urls) > 0 and len(queue) < 20: continue for work in queue: work.start() for work in queue: work.join() while len(queue): work = queue.pop() if work.statue: if work.title == '404 Not Found': continue sheet.write(count, 0, count) sheet.write(count, 1, work.url) sheet.write(count, 2, work.title) sheet.write(count, 3, work.date) sheet.write(count, 4, work.author) sheet.write(count, 5, work.comefrom) sheet.write(count, 6, work.body) text = '' for item in work.urls: text += item + ';' sheet.write(count, 7, text) sheet.write(count, 8, work.keywords) urls += work.urls with open('fudan/' + str(count) + '.html', 'w') as f: f.write(work.html) del work count += 1 excel.save('fudan.xls') print(count) if count > 1500: break
def __init__(self): self.f = xlwt3.Workbook(encoding='utf-8') self.sheet = self.f.add_sheet('sheet', cell_overwrite_ok=True) self.count = 1 head = [ '实地认证', '身份认证', '信用报告', '工作认证', '收入认证', '房产认证', '购车认证', '结婚认证', '学历认证', '手机实名认证', '微博认证', '居住地证明' ] self.sheet.write(0, 0, 'ID') num = 1 for i in head: self.sheet.write(0, num, i) num += 1 self.f.save('data.xls')