File: view.py

package info (click to toggle)
python-scrapy 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,664 kB
  • sloc: python: 52,028; xml: 199; makefile: 25; sh: 7
file content (28 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import argparse
import logging

from scrapy.commands import fetch
from scrapy.http import Response, TextResponse
from scrapy.utils.response import open_in_browser

logger = logging.getLogger(__name__)


class Command(fetch.Command):
    def short_desc(self) -> str:
        return "Open URL in browser, as seen by Scrapy"

    def long_desc(self) -> str:
        return (
            "Fetch a URL using the Scrapy downloader and show its contents in a browser"
        )

    def add_options(self, parser: argparse.ArgumentParser) -> None:
        super().add_options(parser)
        parser.add_argument("--headers", help=argparse.SUPPRESS)

    def _print_response(self, response: Response, opts: argparse.Namespace) -> None:
        if not isinstance(response, TextResponse):
            logger.error("Cannot view a non-text response.")
            return
        open_in_browser(response)