Excel 中将每行批量复制扩展为多行

=INDEX(Sheet1!$A:$A,INT((ROW()-1)/60)+1,)

注:假设要复制的是表sheet1中A行的内容,60表示复制60行。

from DrissionPage import ChromiumPage import csv import re page = ChromiumPage() m = 1 url_csv = r"C:\Users\张雅莉\get_url.csv" result = r"C:\Users\张雅莉\result.csv" with open(fr"{url_csv}", 'r',encoding="utf-8") as f: csvReader = csv.reader(f) for row in csvReader: url = row[1] page.get(url) try: site = page.ele('x://*[@class="baseInfoText"]',timeout=2).attr('text') except: site = '' try: heat = page.ele('x://*[@id="__next"]/div[3]/div/div[3]/div[2]/div[1]/div[2]/div[1]/div',timeout=2).attr('text') except: heat = '' try: open_time = page.ele('x://*[@id="__next"]/div[3]/div/div[4]/div[1]/div[2]/div/div[4]',timeout=2).attr('text') except: open_time = '' try: service_facility = page.ele('x://*[@id="__next"]/div[3]/div/div[4]/div[1]/div[2]/div/div[6]',timeout=2).attr('text') except: service_facility = '' try: presentation = page.ele('x://*[@id="__next"]/div[3]/div/div[4]/div[1]/div[2]/div/div[2]',timeout=2).attr('text') except: presentation = '' try: sum_text = page.ele('x://*[@id="commentModule"]/div[1]',timeout=2).attr('text') sum = int(re.search(r'\d+', sum_text).group()) # 提取数字 except: sum = 0 try: bad_text = page.ele('x://*[@id="commentModule"]/div[3]/span[last()]',timeout=2).attr('text') bad_comment = int(re.search(r'\d+', bad_text).group()) # 提取数字 except: bad_comment = 0 with open(fr"{result}",'a',encoding='utf-8', newline='') as f: # 在文件夹下创建excel表格 csvWriter = csv.writer(f) csvWriter.writerow([row[0],site,presentation,service_facility,open_time,bad_comment,sum,heat,row[2]]) m+=1 print(m)# 将数据输入 print(sum) print(bad_comment) print(site) print(open_time) print(service_facility) print(presentation)修改代码使.csv表格高为17
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值