Package: pydude-pyto
LicenseVersionGithub ActionsCoverageSupported versionsWheelStatusDownloadsAll Contributorsdude uncomplicated data extraction (For Pyto on iOS)dude_pyto is a very simple framework for writing web scrapers using Python decorators.
The design, inspired byFlask, was to easily build a web scraper in just a few lines of code.
dude_pyto has an easy-to-learn syntax.🚨 dude_pyto is currently in Pre-Alpha. Please expect breaking changes.Special Version for PytoThis branch makes Braveblock an optional dependency for use withPytoon iOS.Pyto, and other similar iOS apps, do not support the compilation of code after the app has been approved.So, the Rust-based code of Braveblock will not be downloaded through Pyto.Please visitroniemartinez/dudefor the original repository.InstallationTo install, simply run the following from terminal.pipinstallpydude
playwrightinstall# Install playwright binaries for Chrome, Firefox and Webkit.Minimal web scraperThe simplest web scraper will look like this:fromdude_pytoimportselect@select(css="a")defget_link(element):return{"url":element.get_attribute("href")}The example above will get all thehyperlinkelements in a page and calls the handler functionget_link()for each element.How to run the scraperYou can run your scraper from terminal/shell/command-line by supplying URLs, the output filename of your choice and the paths to your python scripts todude_pyto scrapecommand.dude_pytoscrape--url"<url>"--outputdata.jsonpath/to/script.pyThe output indata.jsonshould contain the actual URL and the metadata prepended with underscore.[
  {
    "_page_number": 1,
    "_page_url": "https://dude.ron.sh/",
    "_group_id": 4502003824,
    "_group_index": 0,
    "_element_index": 0,
    "url": "/url-1.html"
  },
  {
    "_page_number": 1,
    "_page_url": "https://dude.ron.sh/",
    "_group_id": 4502003824,
    "_group_index": 0,
    "_element_index": 1,
    "url": "/url-2.html"
  },
  {
    "_page_number": 1,
    "_page_url": "https://dude.ron.sh/",
    "_group_id": 4502003824,
    "_group_index": 0,
    "_element_index": 2,
    "url": "/url-3.html"
  }
]Changing the output to--output data.csvshould result in the following CSV content.FeaturesSimpleFlask-inspired design - build a scraper with decorators.UsesPlaywrightAPI - run your scraper in Chrome, Firefox and Webkit and leverage Playwright's powerful selector engine supporting CSS, XPath, text, regex, etc.Data grouping - group related results.URL pattern matching - run functions on matched URLs.Priority - reorder functions based on priority.Setup function - enable setup steps (clicking dialogs or login).Navigate function - enable navigation steps to move to other pages.Custom storage - option to save data to other formats or database.Async support - write async handlers.Option to use other parser backends aside from Playwright.BeautifulSoup4-pip install pydude[bs4]Parsel-pip install pydude[parsel]lxml-pip install pydude[lxml]Pyppeteer-pip install pydude[pyppeteer]Selenium-pip install pydude[selenium]Option to follow all links indefinitely (Crawler/Spider).Events - attach functions to startup, pre-setup, post-setup and shutdown events.Option to save data on every page.Supported Parser BackendsBy default, dude_pyto uses Playwright but gives you an option to use parser backends that you are familiar with.
It is possible to use parser backends likeBeautifulSoup4,Parsel,lxml,Pyppeteer,
andSelenium.Here is the summary of features supported by each parser backend.Parser BackendSupportsSync?SupportsAsync?SelectorsSetupHandlerNavigateHandlerCSSXPathTextRegexPlaywright✅✅✅✅✅✅✅✅BeautifulSoup4✅✅✅🚫🚫🚫🚫🚫Parsel✅✅✅✅✅✅🚫🚫lxml✅✅✅✅✅✅🚫🚫Pyppeteer🚫✅✅✅✅🚫✅✅Selenium✅✅✅✅✅🚫✅✅Using the Docker imagePull the docker image using the following command.docker pull roniemartinez/dudeAssuming thatscript.pyexist in the current directory, run Dude using the following command.docker run -it --rm -v "$PWD":/code roniemartinez/dude dude scrape --url <url> script.pyDocumentationRead the complete documentation athttps://roniemartinez.github.io/dude/.
All the advanced and useful features are documented there.Requirements✅ Any dude_pyto should know how to work with selectors (CSS or XPath).✅ Familiarity with any backends that you love (seeSupported Parser Backends)✅ Python decorators... you'll live, dude!Why name this project "dude"?✅ ARecursive acronymlooks nice.✅ Adding "uncomplicated" (likeufw) into the name says it is a very simple framework.✅ Puns! I also think that if you want to do web scraping, there's probably some random dude_pyto around the corner who can make it very easy for you to start with it. 😊AuthorRonie MartinezContributors ✨Thanks goes to these wonderful people (emoji key):Ronie Martinez🚧💻📖🚇This project follows theall-contributorsspecification. Contributions of any kind welcome!