Python + bash
Если вам часто требуется запускать shell команды из Python-кода, какой способ вы используете?
Самый низкоуровневый это функция os.system(), либо os.popen(). Рекомендованный способ это subprocess.call(). Но это всё еще достаточно неудобно.
Советую обратить своё внимание на очень крутую библиотеку sh.
Что она умеет?
🔸 удобный синтаксис вызова команд как функций
# os
import os
os.system("tar cvf demo.tar ~/")
# subprocess
import subprocess
subprocess.call(['tar', 'cvf', 'demo.tar', '~/'])
# sh
import sh
sh.tar('cvf', 'demo.tar', "~/")
🔸 простое создание функции-алиаса для длинной команды
fn = sh.lsof.bake('-i', '-P', '-n')
output = sh.grep(fn(), 'LISTEN')
в этом примере также задействован пайпинг
🔸 удобный вызов команд от sudo
with sh.contrib.sudo:
print(ls("/root"))
Такой запрос спросит пароль. Чтобы это работало нужно соответствующим способом настроить юзера.
А вот вариант с вводом пароля через код.
password = "secret"
sudo = sh.sudo.bake("-S", _in=password+"\n")
print(sudo.ls("/root"))
Это не все фишки. Больше интересных примеров смотрите в документации.
Специально для Windows💀 юзеров
#libs#linux
https://medium.com/towards-data-science/using-scrapy-to-build-your-own-dataset-64ea2d7d4673
In short, #Scrapy is a framework built to build web scrapers more easily and relieve the pain of maintaining them. Basically, it allows you to focus on the data extraction using #CSS selectors and choosing XPath expressions and less on the intricate internals of how spiders are supposed to work.
#scrapy
Scrapy is a fast high-level #web crawling and web scraping framework, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from #data_mining to #monitoring and #automated_testing.
https://github.com/scrapy/scrapy
#python#crawler#feapder#feaplat#python#scrapy#spider
Feapder is a simple, powerful Python web scraping framework (Python 3.6+) with four spider types for different needs, plus breakpoint resuming, monitoring alerts, browser rendering, and massive data deduplication. Install easily via pip (basic, render, or full versions), create a spider with one command, and run it to fetch/parse sites like Baidu. A management system handles deployment/scheduling. This saves you time by making scraping fast, reliable, and scalable without building everything from scratch.
https://github.com/Boris-code/feapder
#webScraping#Python#Scrapy
🐍
Scrapy course - Python web scraping for beginners
The Scrapy #Beginners Course will teach you everything you need to learn to start scraping websites at scale using #Python Scrapy.
Topics
- Creating your first #Scrapy spider
- #Crawling through websites & scraping data from each page
- Cleaning data with Items & Item Pipelines
- Saving data to CSV files, #MySQL & #Postgres#databases
- Using fake #user-agents & headers to avoid getting blocked
- Using #proxies to scale up your web scraping without getting banned
- Deploying your #scraper to the cloud & scheduling it to run periodically
🗣️ Joe Kearney.
🔗Link
📢#youtube
⭐️ Resources ⭐️
Course Resources
- Scrapy Docs
- Course Guide
- Course Github
- The Python Scrapy Playbook
-----
Main channel: @repo_science
Coupons: @freecoupons_reposcience
-----