Skip to content

Releases: roniemartinez/dude

🔨 Run adblock on HTTPX request event hook

31 Mar 18:45
0.15.0
d19cc29
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 0.14.0...0.15.0

✨ Use fnmatch

29 Mar 19:23
0.14.0
3f76a0f
Compare
Choose a tag to compare

What's Changed

Other

fnmatch: URL pattern matcher now uses Unix style wildcards (fnmatch) instead of regex

See: https://docs.python.org/3/library/fnmatch.html

Wildcards are easier to understand and simpler to use compared to regular expressions

- @select(css=".title", url=r".*\.com")
+ @select(css=".title", url="*.com/*")
def result_title(element):
    return {"title": element.text_content()}

Full Changelog: 0.13.0...0.14.0

✨ Make return value of decorated functions optional

27 Mar 17:55
0.13.0
8dc9963
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.12.2...0.13.0

🐛 Fix PlaywrightScraper overwriting output file

27 Mar 17:19
0.12.2
85ee82d
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.12.1...0.12.2

🔨 Refactor for Alpha

27 Mar 13:10
0.12.1
1691813
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.12.0...0.12.1

✨ Add shutdown event and save per page option

25 Mar 20:49
0.12.0
35f900b
Compare
Choose a tag to compare

What's Changed

Other

Full Changelog: 0.11.0...0.12.0

✨ Save data on each page

You can now save data after scraping a page. Save functions should be decorated with is_per_page=True and execute the scraper with --save-per-page to use it.

@save("jsonl", is_per_page=True)
def save_jsonl(data, output) -> bool:
    global jsonl_file
    jsonl_file.writelines((json.dumps(item) + "\n" for item in data))
    return True

✨ Shutdown event

The shutdown even is called before the application terminates. This is useful when freeing resources, file handles, databases or other use-cases before ending.

@shutdown()
def zip_all():
    global SAVE_DIR
    shutil.make_archive("images-and-pdfs", "zip", SAVE_DIR)

✨ How dude runs internally

events

✨ Events and Basic Spider

23 Mar 19:22
0.11.0
37ccfff
Compare
Choose a tag to compare

What's Changed

Features

Documentation

Fixes

Other

✨ Basic Spider

Example

dude scrape ... --follow-urls

or

if __name__ == "__main__":
    import dude

    dude.run(..., follow_urls=True)

✨ Events

More details at https://roniemartinez.github.io/dude/advanced/14_events.html

Example

import uuid
from pathlib import Path

from dude import post_setup, pre_setup, startup

SAVE_DIR: Path


@startup()
def initialize_csv():
    """
    Connection to databases or API and other use-cases can be done here before the web scraping process is started.
    """
    global SAVE_DIR
    SAVE_DIR = Path(__file__).resolve().parent / "temp"
    SAVE_DIR.mkdir(exist_ok=True)


@pre_setup()
def screenshot(page):
    """
    Perform actions here after loading a page (or after a successful HTTP response) and before modifying things in the
    setup stage.
    """
    unique_name = str(uuid.uuid4())
    page.screenshot(path=SAVE_DIR / f"{unique_name}.png")  # noqa


@post_setup()
def print_pdf(page):
    """
    Perform actions here after running the setup stage.
    """
    unique_name = str(uuid.uuid4())
    page.pdf(path=SAVE_DIR / f"{unique_name}.pdf")  # noqa


if __name__ == "__main__":
    import dude

    dude.run(urls=["https://dude.ron.sh"])

Diagram showing when events are executed

image

Full Changelog: 0.10.1...0.11.0

🏁 Fix Windows support

13 Mar 18:37
0.10.1
ed75a77
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.10.0...0.10.1

✨ Block ads

13 Mar 15:57
0.10.0
f0cf10a
Compare
Choose a tag to compare

What's Changed

Added

Changed

Full Changelog: 0.9.2...0.10.0

🔧 Disable notifications

12 Mar 14:20
0.9.2
d51bb02
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.9.1...0.9.2