Skip to main content

Scrapy extension for handle pages with selenium

Project description

ScrapeWebdriver

Class based on selenium webdriver.Firefox with methods for scraping. Allow dynamically change proxies with change of `"about:config".

Changelog presented in CHANGELOG.md.

Installation

pip install scrapy_webdriver

Basic usage

For use selenium, need to yield SeleniumRequest and if you need to make some actions on page, can use driver_func.

from typing import Iterable
import scrapy 
from scrapy.http import Request

from scrapy_webdriver.middleware_utils.drivers import Driver
from scrapy_webdriver.middleware_utils.http import SeleniumRequest


class TestSpider(scrapy.Spider):
    name = "simple_spider"
    start_urls = ["http://example.org"]

    def start_requests(self) -> Iterable[Request]:
        for url in self.start_urls:
            yield SeleniumRequest(
                url=url,
                callback=self.parse,
                driver_func=self.parse_page_with_driver,
            )

    def parse_page_with_driver(self, driver: Driver):
        self.logger.info("Page opened")

    def parse(self, response, **kwargs):
        yield {"title": response.css("title::text").get()}

Available options

  • SELENIUM_POOL_SIZE - how many concurrent browser instances will be opened at same time, default 1
  • SELENIUM_PROXY_POOL - proxy pool in format Iteable[http://user:pass@host:port], default ().
  • SELENIUM_CHANGE_PROXY_ON_EACH_REQUEST - change or not proxy before each request, default True.
  • SELENIUM_INSTALL_ADBLOCK - install adblock extension for block some requests, default True.
  • SELENIUM_RUN_PYVIRTUAL_DISPLAY - run py virtual display for not run drivers in headless on server, default False.
  • SELENIUM_HEADLESS - run headless or not.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_webdriver-1.0.9.tar.gz (8.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_webdriver-1.0.9-py3-none-any.whl (8.9 MB view details)

Uploaded Python 3

File details

Details for the file scrapy_webdriver-1.0.9.tar.gz.

File metadata

  • Download URL: scrapy_webdriver-1.0.9.tar.gz
  • Upload date:
  • Size: 8.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.11 Linux/5.15.0-135-generic

File hashes

Hashes for scrapy_webdriver-1.0.9.tar.gz
Algorithm Hash digest
SHA256 d4abfc22980dcb9a0739df1f983ad7bff1508c2657fe05ce1add4096e355af0c
MD5 29fd3c9351301008f38b41f74eaeb57a
BLAKE2b-256 94e7d7f6862fa81befafc6d3de598809214ca0e6916941438c6599af65302dbe

See more details on using hashes here.

File details

Details for the file scrapy_webdriver-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: scrapy_webdriver-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 8.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.11 Linux/5.15.0-135-generic

File hashes

Hashes for scrapy_webdriver-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5d4fd9080ebc6514069f00f682f3dfa78d2bd2b4e45ce5dfc2c4e2ab3762c696
MD5 0d12376f22a7b8096d12ffa4ca1e21d6
BLAKE2b-256 27aafdca4f68c8c8ea5fdb347c22b03bc7fdf63413ffa6a846f6ecfc020a7877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page