当前位置:网站首页>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
边栏推荐
- When dialogfragment's onstop is completely invisible, call disass to exit the interface and report an error. Solution
- Behaviortree in ros2
- 再次上榜!知道创宇入选2022中国网安产业竞争力50强
- 表单校验问题——el-select(初始化页面自动触发校验解决办法)
- [stm32 HAL库] RTC和BKP驱动
- 2022 PMP project management examination agile knowledge points (4)
- 股票开户在网上开通安全吗?
- What will be done after digital IC Verification?
- Chapter V virtual memory exercise
- pymysql.Error 获取错误码与具体错误信息
猜你喜欢

Web API learning notes 1

Matlab learning notes (6) upsample function and downsample function of MATLAB
![[API packet capturing in selenium automation] installation and configuration of browsermobproxy](/img/67/3e15b2191ee23a8c4453aad007651d.png)
[API packet capturing in selenium automation] installation and configuration of browsermobproxy

Tanghongbin, Yaya live CTO: to truly localize, the product should not have the attribute of "origin"

lock4j--分布式锁中间件--使用/实例

【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头
![[conception de la machine d'état] Moore, Mealy State Machine, Three - stage, Two - stage, one - stage State Machine Writing Specification](/img/48/e29f34aff7cc437bfb574591d54e3d.png)
[conception de la machine d'état] Moore, Mealy State Machine, Three - stage, Two - stage, one - stage State Machine Writing Specification

PHP 使用endroid/qrcode 二维码生成, GD库生成分享海报
![[stm32 Hal library] RTC and BKP drives](/img/72/c2c46377d0a2a5a032802640ca0201.png)
[stm32 Hal library] RTC and BKP drives

Cmake tutorial (I)
随机推荐
Association line exploration, how to connect the two nodes of the flow chart
在DialogFragment的onStop(完全不可见)时调用dismiss退出界面报错解决办法
C語言-單詞分析解析
Non scientific class! The road of self-study!
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
CIN at QT (the clearest tutorial in the whole network)
Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering
MSCI 2022 market classification assessment
frameworks/base/core/res/res/values/symbols.xml:3915: error: no definition for declared symbol解决办法
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
Web API learning notes 1
CMake教程(一)
CS5463代码模块解析(包含下载链接)
Advice to friends
[数学建模]Matlab非线性规划之fmincon()函数
See fengzhixia | FENGZikai, the originator of Guoman, for exclusive sale of Digital Collections
云计算的迷路者
入行数字IC验证后会做些什么?
Design e-commerce seckill system
At the end of June, how many people in Kangkang are ready to change jobs