{"id":19899997,"url":"https://github.com/scrapy-plugins/scrapy-headless","last_synced_at":"2025-05-02T22:32:05.967Z","repository":{"id":52468145,"uuid":"237973328","full_name":"scrapy-plugins/scrapy-headless","owner":"scrapy-plugins","description":null,"archived":false,"fork":false,"pushed_at":"2021-04-28T07:45:51.000Z","size":22,"stargazers_count":29,"open_issues_count":4,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T09:07:04.715Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scrapy-plugins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-03T13:37:14.000Z","updated_at":"2024-06-13T02:53:48.000Z","dependencies_parsed_at":"2022-08-31T03:11:06.781Z","dependency_job_id":null,"html_url":"https://github.com/scrapy-plugins/scrapy-headless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapy-plugins%2Fscrapy-headless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapy-plugins%2Fscrapy-headless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapy-plugins%2Fscrapy-headless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrapy-plugins%2Fscrapy-headless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scrapy-plugins","download_url":"https://codeload.github.com/scrapy-plugins/scrapy-headless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252116440,"owners_count":21697378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T20:10:46.499Z","updated_at":"2025-05-02T22:32:04.371Z","avatar_url":"https://github.com/scrapy-plugins.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scrapy Headless\n\nThis is a plugin to make it easier to use scrapy with headless browsers, at the moment it only works with selenium grid as a driver.\n\n## Installation\n\nFor now the project is in a private bit bucket repo, so install it from there:\n```\npip install scrapy-headless\n```\n\n## Usage\n\nYou will first need to have a selenium grid server running, you may find some examples on:  https://github.com/SeleniumHQ/docker-selenium/wiki/Getting-Started-with-Docker-Compose\n\nThe easiest way is by using docker-compose, here is a example docker-compose.yml file:\n\n```yml\nselenium-hub:\n  image: selenium/hub\n  ports:\n  - 4444:4444\n\nchrome:\n  image: selenium/node-chrome\n  links:\n  - selenium-hub:hub\n  environment:\n    - HUB_PORT_4444_TCP_ADDR=hub\n    - GRID_TIMEOUT=180 # Default timeout is 30s might be low for Selenium\n  volumes:\n  - /dev/shm:/dev/shm\n```\n\nAnd just,\n```\n$ docker-compose up -d\n```\n\nAnd, if you want more browser instances\n```\n$ docker-compose up -d --scale chrome=3 # For 3 browsers\n```\n\nOn scrapy you will need to update your settings, for example:\n```py\nfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n\nSELENIUM_GRID_URL = 'http://localhost:4444/wb/hub'  # Example for local grid with docker-compose\nSELENIUM_NODES = 1  # Number of nodes(browsers) you are running on your grid\nSELENIUM_CAPABILITIES = DesiredCapabilities.CHROME  # Example for Chrome\n\n# You need also to change the default download handlers, like so:\nDOWNLOAD_HANDLERS = {\n    \"http\": \"scrapy_selenium.SeleniumDownloadHandler\",\n    \"https\": \"scrapy_selenium.SeleniumDownloadHandler\",\n}\n```\n\nYou may also set a proxy for your selenium requests:\n```py\nSELENIUM_PROXY = 'http://proxy.url:port'\n```\n\nNow all you need to do, is on your spider, for the requests you want handled by selenium use `HeadlessRequest` instead of scrapy's Request, for example:\n```py\nfrom scrapy import Spider\nfrom scrapy_headless import HeadlessRequest\n\n\nclass SomeSpider(Spider):\n    ...\n    def some_parser(self, response):\n        ...\n        yield HeadlessRequest(some_url, callback=self.other_parser)\n```\n\nIf you need to do something with the driver after getting the url you may also set a `driver_callback`:\n```py\nfrom scrapy import Spider\nfrom scrapy_headless import HeadlessRequest\n\n\nclass SomeSpider(Spider):\n    ...\n    def some_parser(self, response):\n        ...\n        yield HeadlessRequest(some_url, callback=self.other_parser, driver_callback=self.process_webdriver)\n\n    def process_webdriver(self, driver):\n        ...\n```\n\n## Future\nIdeally this download handler should be able to use any of the following:\n\n- [x] Selenium Grid\n- [ ] Selenium (without grid)\n- [ ] Pyppeteer","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapy-plugins%2Fscrapy-headless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrapy-plugins%2Fscrapy-headless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrapy-plugins%2Fscrapy-headless/lists"}