当前位置:网站首页>Scrapy uses xlwt to implement the exporter that exports data in Excel format
Scrapy uses xlwt to implement the exporter that exports data in Excel format
2022-06-28 23:25:00 【supramolecular】
from scrapy.exporters import BaseItemExporter
import xlwt
from openpyxl import Workbook
from scrapy.exporters import BaseItemExporter
import xlwt
class ExcelItemExporter(BaseItemExporter):
def __init__(self, file, **kwargs):
self._configure(kwargs)
self.file = file
self.wbook = xlwt.Workbook(encoding='utf-8')
self.wsheet = self.wbook.add_sheet('data')
self.row = 0
sheet_title = {
"question_id": ' problem id',
"question": ' problem ',
"question_all": ' Number of answers ',
"url": " link ",
"answer": " answer ",
"evaluate_num": " Number of likes ",
"keyword_nums": " Keyword occurrence times ",
"best_answer": " Is the best answer ",
"username": " User name ",
"published_time": " Release time ",
"answer_id": ' answer id'
}
self.write_title(sheet_title)
def finish_exporting(self):
self.wbook.save(self.file)
def export_item(self, item):
fields = self._get_serialized_fields(item)
for col, v in enumerate(x for _, x in fields):
# print(self.row, col, v)
self.wsheet.write(self.row, col, v)
self.row += 1
def write_title(self, item):
fields = self._get_serialized_fields(item)
for col, v in enumerate(x for _, x in fields):
# print(self.row, col, v)
self.wsheet.write(self.row, col, v)
self.row += 1
边栏推荐
- frameworks/base/core/res/res/values/symbols.xml:3915: error: no definition for declared symbol解决办法
- Would like to ask, how to open a stock account? Is it safe to open an account online?
- C language - word analysis
- Prometeus 2.36.0 new features
- C interview questions_ 20220627 record
- TDD案例实战
- Is it safe to open a stock account on the Internet?
- 2022-06-28: what does the following golang code output? A:true; B:false; C:panic; D: Compilation failed. package main import “fm
- 两栏布局左边图片显示部分由右边内容高度决定
- PHP利用CURL实现登录网站后下载Excel文件
猜你喜欢

再次上榜!知道创宇入选2022中国网安产业竞争力50强

Interviewer: what is the internal implementation of strings in redis?

The picture display on the left of the two column layout is determined by the content height on the right

【狀態機設計】Moore、Mealy狀態機、三段式、二段式、一段式狀態機書寫規範

Web API learning notes 1

At the end of June, how many people in Kangkang are ready to change jobs
![[word Tutorial Series Part 1] how to remove arrows in word tables](/img/c7/dc57002b0e9d433c4dfac15d53713d.png)
[word Tutorial Series Part 1] how to remove arrows in word tables

One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards
![[mathematical modeling] fmincon() function of MATLAB nonlinear programming](/img/fc/46949679859b1369fcc83d0d8b637c.png)
[mathematical modeling] fmincon() function of MATLAB nonlinear programming

C# 面试题目_20220627记录一下
随机推荐
月薪6万,互联网“降本增效”后,这类人开始被疯抢
Yyds dry inventory solution sword finger offer: maximum sum of continuous subarrays (II)
Counting sorting and stability of sorting
【OpenCV】—线性滤波:方框滤波、均值滤波、高斯滤波
LeetCode 324 擺動排序 II[排序 雙指針] HERODING的LeetCode之路
设计电商秒杀系统
ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
Keil project, RTT cannot print after too many programs are written
Serious internal entanglement in the we media industry: where should the enterprise we media go
【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头
Advice to friends
Undefined symbol main (referred from entry9a.o).
Matlab learning notes (6) upsample function and downsample function of MATLAB
2022年PMP项目管理考试敏捷知识点(4)
这样学习二叉树
Scrapy使用xlwt实现将数据以Excel格式导出的Exporter
第二章 经典同步练习作业
第三章 处理机调度练习
Is the account opening of Guosheng securities really safe and reliable