Skip to main content

Scralenium

GitHub repo size GitHub License PyPI - Downloads GitHub Last Commit CI CI GitHub repo size codecov

Project name is a scralenium that allows use selenium webdriver with scrapy to do scrape web data from dynamic web pages. The name is actually really clever, if you didn't notice it is scrapy + selenium = scralenium. Genius right? :)

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed the latest version of python 3
  • You are familiar with the scrapy framework
  • You are familiar with selenium
  • You have a webdriver installed/available

Requirements:

  • scrapy
  • selenium

Installing

To install scralenium, follow these steps:

git clone https://github.com/alexpdev/scralenium.git
cd scralenium
pip install .

From PyPi

pip install scralenium

License

This project uses the following license: Apache 2.0.

Usage

Using scralenium is really simple.

In your scrappy settings set the SELENIUM_DRIVER_NAME and SELENIUM_DRIVER_EXECUTABLE fields. scralenium currently supports chrome SELENIUM_DRIVER_NAME field. If the webdriver executable is already on path then it can be omitted. You also need to enable the ScraleniumDownloaderMiddleware in the DOWNLOADER_MIDDLEWARES feed.

from shutil import which
SELENIUM_DRIVER_EXECUTABLE = which("chromedriver")
SELENIUM_DRIVER_NAME = "chrome"
DOWNLOADER_MIDDLEWARES = {
    "scralenium.ScraleniumDownloaderMiddleware" : 950
}

Once you have added the settings to the settings.py file or in the spider's custom_settings attribute all that is needed is to use ScraleniumRequest when yielding from the start_requests method or from your parse callback methods. The pause argument can be used to set the webdrivers implicit wait value. And the response argument in the parse callback methods gives you full access to the normal scrapy response as well as all the features of the webdriver.

import scrapy
from scralenium import ScraleniumRequest
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

class MySpider(scrapy.Spider):
    """Example of using scrapy.Spider with ScraleniumRequest"""
    ...
     
    def start_requests(self):
        for url in self.start_urls:
            yield ScreleniumRequest(url, callback=self.parse, pause=4)
    
    def parse(self, response):
        html = response.text
        title = response.xpath("//title/text()").get()
        element = response.find_element(By.ID, "submit-button")
        element.send_keys(Keys.Return)
        next_page = response.xpath("//a[@class='next-page-link']/@href").get()
        next_url = response.urljoin(next_page)
        yield ScraleniumRequest(next_url, callback=self.parse, pause=4)
        yield {"title": title}

I have added some additional features but am behind on documenting them.

TODO

[x] add features
[] document them

Metadata

Release files for scralenium 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scralenium 0.1.3
File Size Uploaded
scralenium-0.1.3.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scralenium 0.1.3
File Interpreter ABI Platform
scralenium-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / scralenium-0.1.3.tar.gz

Download URL scralenium-0.1.3.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c38a43d5c37dd0bed6cd4f862f874d20a7e41215792ef2059e3797389c07f999
BLAKE2b-256 checksum
How to use checksums
525b853d435b1080ed966e711478707781fd9b339354a75904957efbc270dcc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / scralenium-0.1.3-py3-none-any.whl

Download URL scralenium-0.1.3-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52abaa98d1669244a8a9babccce2cc2fd2ed438ce10e3dde89dfc035a4d6b41a
BLAKE2b-256 checksum
How to use checksums
7693e490111b058c4cfaa1f5ec157245b2f55c1eb16c04c8ef37303eac283c92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page