- 전체
- Python 일반
- Python 수학
- Python 그래픽
- Python 자료구조
- Python 인공지능
- Python 인터넷
- Python SAGE
- wxPython
- TkInter
- iPython
- wxPython
- pyQT
- Jython
- django
- flask
- blender python scripting
- python for minecraft
- Python 데이터 분석
- Python RPA
- cython
- PyCharm
- pySide
- kivy (python)
Python 인터넷 Pipeline to Download PDF or Save page as PDF for scrapy item
2021.06.26 23:25
Project description
Pipeline to Download PDF or Save page as PDF for scrapy item
Installation
Install scrapy-save-as-pdf using pip:
pip install scrapy-save-as-pdf
Configuration
- (Optionally) if you want to use
WEBDRIVER_HUB_URL, you can usedockerto setup one like this:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-alpha-7-20201119
then WEBDRIVER_HUB_URL value is http://docker_host_ip:4444/wd/hub and we often debug on local host, so we use http://127.0.0.1:4444/wd/hub
- Add the
settings.pyof your Scrapy project like this:
PROXY = "" CHROME_DRIVER_PATH ='/snap/bin/chromium.chromedriver' PDF_SAVE_PATH = "./pdfs" PDF_SAVE_AS_PDF = False PDF_DOWNLOAD_TIMEOUT = 60 PDF_PRINT_OPTIONS = { 'landscape': False, 'displayHeaderFooter': False, 'printBackground': True, 'preferCSSPageSize': True, } WEBDRIVER_HUB_URL = 'http://127.0.0.1:4444/wd/hub'
If both WEBDRIVER_HUB_URL and CHROME_DRIVER_PATH are set, we use WEBDRIVER_HUB_URL.
- Enable the pipeline by adding it to
ITEM_PIPELINESin yoursettings.pyfile and changing priority:
ITEM_PIPELINES = { 'scrapy_save_as_pdf.pipelines.SaveAsPdfPipeline': -1, }
The order should before your persist pipeline such as save to database and after your preprocess pipeline.
In the demo scrapy project, I put the SaveToQiniuPipeline after this plugin to persist pdf to the cloud.
Usage
set the pdf_url and/or url field in your yielded item
import scrapy class MySpider(scrapy.Spider): start_urls = [ "http://example.com", ] def start_requests(self): for url in self.start_urls: yield scrapy.Request(url, self.parse) def parse(self, response): yield { "url": "http://example.com/cate1/page1.html", "pdf_url": "http://example.com/cate1/page1.pdf", } yield { "url": "http://example.com/cate1/page2.html", "pdf_url": "http://example.com/cate1/page2.pdf", }
the pdf_url field will be populated with the downloaded pdf file location, if pdf_url field has old value then move it to origin_pdf_url field, you can handle them in your next pipeline.
Getting help
Please use github issue
Contributing
PRs are always welcomed.
Changes
0.1.0 (2020-12-25)
Initial release
[출처] https://pypi.org/project/scrapy-save-as-pdf/
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 11 |
[PyQT5] PyQt5 Mainwindow에 Qt Designer를 사용한 graph Widget 추가
| 졸리운_곰 | 2024.06.06 | 476 |
| 10 |
[PyQT5] [Python with Pyqt5] Widget에다가 그래프 넣기 (Feat. Matplotlib)
| 졸리운_곰 | 2024.06.06 | 437 |
| 9 |
[PyQT5] 파이썬(Python)PyQt5 - QMessageBox 사용하기
| 졸리운_곰 | 2024.06.06 | 455 |
| 8 |
[PyQT5] UI Designer 에서 Tab Widget 생성 하기
| 졸리운_곰 | 2024.06.06 | 420 |
| 7 |
[PyQT5] UI Designer 에서 리사이즈 시 같이 확장하기
| 졸리운_곰 | 2024.06.06 | 537 |
| 6 |
[PyQT5] UI Designer 에서 Grid Layout 배치 해보기
| 졸리운_곰 | 2024.06.06 | 474 |
| 5 |
[pyQT] 「Python : PyQt5」 Qt Designer : .ui → .py 변환
| 졸리운_곰 | 2024.06.05 | 624 |
| 4 |
[pyQT] Dev/python/ [pyqt5] 프로그램창을 항상 가장 위에 있게 하면서 동시에 타이틀 바도 없게 하려면?
| 졸리운_곰 | 2024.06.01 | 542 |
| 3 |
[pyQT] QtDesigner에서 리소스 편집기 사용하기
| 졸리운_곰 | 2024.05.28 | 499 |
| 2 |
[pyQT] Qt Resource 파일 (.qrc) 적용방법
| 졸리운_곰 | 2024.05.28 | 421 |
| 1 | [pyQT] from PyQt5.QtChart import QLineSeries, QChart, QValueAxis, QDateTimeAxis ImportError: DLL load failed while importing QtChart: 지정된 모듈을 찾을 수 없습니다. | 졸리운_곰 | 2024.01.28 | 430 |

