Три способа выполнить множество задач с asyncio
Функция для примера:
async def do_it(n):
await asyncio.sleep(random.uniform(0.5, 1))
return n
1. Последовательный вызов
async def main():
for i in range(100):
result = await do_it(i)
Такой вызов имеет смысл только тогда, когда результат одной задачи требуется для вызова следующей.
Если они независимы, то это антипаттерн, так как аналогичен простому синхронному вызову по очереди.
2. Упорядоченный результат
async def main():
tasks = [do_it(i) for i in range(100)]
results = await asyncio.gather(*tasks)
Выполняет корутины конкурентно и возвращает результат в виде списка.
Полезен когда требуется получить результаты в том же порядке в котором задачи отправлены.
3. Результат по мере готовности
tasks = [asyncio.create_task(do_it(i)) for i in range(100)]
for cor in asyncio.as_completed(tasks):
result = await cor
Так же выполняет корутины конкурентно, но не гарантирует порядок. Результат возвращается по мере готовности, каждый отдельно.
Полезен когда нужно обработать любой ответ как можно скорее.
#async
#python#crawler#crawling#framework#hacktoberfest#python#scraping#web_scraping#web_scraping_python
Scrapy is a powerful tool for extracting data from websites. It works on many platforms and requires Python 3.9 or higher. Scrapy is free, stable, and can handle complex tasks efficiently. It allows you to manage multiple requests at once, making it fast and efficient for large-scale data extraction. Scrapy also supports various formats for storing data and has features like auto-throttling to prevent overwhelming websites. This makes it a great choice for users who need to collect data from many websites quickly and reliably.
https://github.com/scrapy/scrapy
#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
-----
#python#ai#ai_scraping#automation#crawler#crawling#crawling_python#data#data_extraction#mcp#mcp_server#playwright#python#scraping#selectors#stealth#web_scraper#web_scraping#web_scraping_python#webscraping#xpath
Scrapling is a fast Python web scraping tool that fetches pages, bypasses anti-bot blocks like Cloudflare, and adapts to site changes by auto-finding elements. Use simple CSS/XPath selectors, spiders for big crawls with pause/resume, proxy rotation, and CLI—no code needed sometimes. Install via pip; it's memory-light and beats others in speed. You save time fixing broken scrapers, scrape reliably at scale, cut costs with AI tools, and focus on using data for leads, prices, or research.
https://github.com/D4Vinci/Scrapling