docs: update the translated readme files with the new content
This commit is contained in:
+205
-137
@@ -6,8 +6,9 @@
|
||||
</picture>
|
||||
</a>
|
||||
<br>
|
||||
<small>Web Scraping have never been easier!</small>
|
||||
<small>Effortless Web Scraping for the Modern Web</small>
|
||||
</h1>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/D4Vinci/Scrapling/actions/workflows/tests.yml" alt="Tests">
|
||||
<img alt="Tests" src="https://github.com/D4Vinci/Scrapling/actions/workflows/tests.yml/badge.svg"></a>
|
||||
@@ -28,46 +29,47 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/parsing/selection/">
|
||||
選択メソッド
|
||||
</a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/fetching/choosing/">
|
||||
フェッチャーの選択
|
||||
</a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/cli/overview/">
|
||||
CLI
|
||||
</a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/ai/mcp-server/">
|
||||
MCPモード
|
||||
</a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/tutorials/migrating_from_beautifulsoup/">
|
||||
Beautifulsoupからの移行
|
||||
</a>
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/parsing/selection/"><strong>選択メソッド</strong></a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/fetching/choosing/"><strong>Fetcherの選び方</strong></a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/cli/overview/"><strong>CLI</strong></a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/ai/mcp-server/"><strong>MCPモード</strong></a>
|
||||
·
|
||||
<a href="https://scrapling.readthedocs.io/en/latest/tutorials/migrating_from_beautifulsoup/"><strong>Beautifulsoupからの移行</strong></a>
|
||||
</p>
|
||||
|
||||
**アンチボットシステムとの戦いをやめましょう。ウェブサイトが更新されるたびにセレクタを書き直すのをやめましょう。**
|
||||
Scraplingは、単一のリクエストから本格的なクロールまですべてを処理する適応型Web Scrapingフレームワークです。
|
||||
|
||||
Scraplingは単なるウェブスクレイピングライブラリではありません。ウェブサイトの変更から学習し、それとともに進化する最初の**適応型**スクレイピングライブラリです。他のライブラリがウェブサイトの構造が更新されると壊れる一方で、Scraplingは自動的に要素を再配置し、スクレイパーを稼働し続けます。
|
||||
そのパーサーはウェブサイトの変更から学習し、ページが更新されたときに要素を自動的に再配置します。Fetcherはすぐに使えるCloudflare Turnstileなどのアンチボットシステムを回避します。そしてSpiderフレームワークにより、Pause & Resumeや自動Proxy回転機能を備えた並行マルチSessionクロールへとスケールアップできます — すべてわずか数行のPythonで。1つのライブラリ、妥協なし。
|
||||
|
||||
モダンウェブ向けに構築されたScraplingは、**独自の高速パースエンジン**とフェッチャーを備えており、あなたが直面する、または直面するであろうすべてのウェブスクレイピングの課題に対応します。ウェブスクレイパーによってウェブスクレイパーと一般ユーザーのために構築され、誰にでも何かがあります。
|
||||
リアルタイム統計とStreamingによる超高速クロール。Web Scraperによって、Web Scraperと一般ユーザーのために構築され、誰にでも何かがあります。
|
||||
|
||||
```python
|
||||
>> from scrapling.fetchers import Fetcher, AsyncFetcher, StealthyFetcher, DynamicFetcher
|
||||
>> StealthyFetcher.adaptive = True
|
||||
# レーダーの下でウェブサイトのソースを取得!
|
||||
>> page = StealthyFetcher.fetch('https://example.com', headless=True, network_idle=True)
|
||||
>> print(page.status)
|
||||
200
|
||||
>> products = page.css('.product', auto_save=True) # ウェブサイトのデザイン変更に耐えるデータをスクレイプ!
|
||||
>> # 後でウェブサイトの構造が変わったら、`adaptive=True`を渡す
|
||||
>> products = page.css('.product', adaptive=True) # そしてScraplingはまだそれらを見つけます!
|
||||
from scrapling.fetchers import Fetcher, AsyncFetcher, StealthyFetcher, DynamicFetcher
|
||||
StealthyFetcher.adaptive = True
|
||||
page = StealthyFetcher.fetch('https://example.com', headless=True, network_idle=True) # レーダーの下でウェブサイトを取得!
|
||||
products = page.css('.product', auto_save=True) # ウェブサイトのデザイン変更に耐えるデータをスクレイプ!
|
||||
products = page.css('.product', adaptive=True) # 後でウェブサイトの構造が変わったら、`adaptive=True`を渡して見つける!
|
||||
```
|
||||
または本格的なクロールへスケールアップ
|
||||
```python
|
||||
from scrapling.spiders import Spider, Response
|
||||
|
||||
class MySpider(Spider):
|
||||
name = "demo"
|
||||
start_urls = ["https://example.com/"]
|
||||
|
||||
async def parse(self, response: Response):
|
||||
for item in response.css('.product'):
|
||||
yield {"title": item.css('h2::text').get()}
|
||||
|
||||
MySpider().start()
|
||||
```
|
||||
|
||||
# スポンサー
|
||||
|
||||
# スポンサー
|
||||
|
||||
<!-- sponsors -->
|
||||
|
||||
@@ -91,138 +93,211 @@ Scraplingは単なるウェブスクレイピングライブラリではあり
|
||||
|
||||
## 主な機能
|
||||
|
||||
### セッションサポート付き高度なウェブサイト取得
|
||||
- **HTTPリクエスト**:`Fetcher`クラスで高速でステルスなHTTPリクエスト。ブラウザのTLSフィンガープリント、ヘッダーを模倣し、HTTP3を使用できます。
|
||||
- **動的読み込み**:Playwright's ChromiumとGoogle Chromeをサポートする`DynamicFetcher`クラスを通じた完全なブラウザ自動化で動的ウェブサイトを取得。
|
||||
- **アンチボット回避**:`StealthyFetcher`とフィンガープリント偽装による高度なステルス機能。自動化でCloudflareのTurnstile/Interstitialのすべてのタイプを簡単に回避できます。
|
||||
- **セッション管理**:リクエスト間でCookieと状態を管理するための`FetcherSession`、`StealthySession`、`DynamicSession`クラスによる永続的なセッションサポート。
|
||||
- **非同期サポート**:すべてのフェッチャーと専用非同期セッションクラス全体での完全な非同期サポート。
|
||||
### Spider — 本格的なクロールフレームワーク
|
||||
- 🕷️ **Scrapy風のSpider API**:`start_urls`、async `parse` callback、`Request`/`Response`オブジェクトでSpiderを定義。
|
||||
- ⚡ **並行クロール**:設定可能な並行数制限、ドメインごとのスロットリング、ダウンロード遅延。
|
||||
- 🔄 **マルチSessionサポート**:HTTPリクエストとステルスヘッドレスブラウザの統一インターフェース — IDによって異なるSessionにリクエストをルーティング。
|
||||
- 💾 **Pause & Resume**:Checkpointベースのクロール永続化。Ctrl+Cで正常にシャットダウン;再起動すると中断したところから再開。
|
||||
- 📡 **Streamingモード**:`async for item in spider.stream()`でリアルタイム統計とともにスクレイプされたアイテムをStreamingで受信 — UI、パイプライン、長時間実行クロールに最適。
|
||||
- 🛡️ **ブロックされたリクエストの検出**:カスタマイズ可能なロジックによるブロックされたリクエストの自動検出とリトライ。
|
||||
- 📦 **組み込みエクスポート**:フックや独自のパイプライン、または組み込みのJSON/JSONLで結果をエクスポート。それぞれ`result.items.to_json()` / `result.items.to_jsonl()`を使用。
|
||||
|
||||
### Sessionサポート付き高度なウェブサイト取得
|
||||
- **HTTPリクエスト**:`Fetcher`クラスで高速かつステルスなHTTPリクエスト。ブラウザのTLS fingerprint、ヘッダーを模倣し、HTTP/3を使用可能。
|
||||
- **動的読み込み**:PlaywrightのChromiumとGoogle Chromeをサポートする`DynamicFetcher`クラスによる完全なブラウザ自動化で動的ウェブサイトを取得。
|
||||
- **アンチボット回避**:`StealthyFetcher`とfingerprint偽装による高度なステルス機能。自動化でCloudflareのTurnstile/Interstitialのすべてのタイプを簡単に回避。
|
||||
- **Session管理**:リクエスト間でCookieと状態を管理するための`FetcherSession`、`StealthySession`、`DynamicSession`クラスによる永続的なSessionサポート。
|
||||
- **Proxy回転**:すべてのSessionタイプに対応したラウンドロビンまたはカスタム戦略の組み込み`ProxyRotator`、さらにリクエストごとのProxyオーバーライド。
|
||||
- **ドメインブロック**:ブラウザベースのFetcherで特定のドメイン(およびそのサブドメイン)へのリクエストをブロック。
|
||||
- **asyncサポート**:すべてのFetcherおよび専用asyncSessionクラス全体での完全なasyncサポート。
|
||||
|
||||
### 適応型スクレイピングとAI統合
|
||||
- 🔄 **スマート要素追跡**:インテリジェントな類似性アルゴリズムを使用してウェブサイトの変更後に要素を再配置。
|
||||
- 🎯 **スマート柔軟選択**:CSSセレクタ、XPathセレクタ、フィルタベース検索、テキスト検索、正規表現検索など。
|
||||
- 🔍 **類似要素を見つける**:見つかった要素に類似した要素を自動的に特定。
|
||||
- 🤖 **AIと使用するMCPサーバー**:AI支援ウェブスクレイピングとデータ抽出のための組み込みMCPサーバー。MCPサーバーは、AI(Claude/Cursorなど)に渡す前にScraplingを活用してターゲットコンテンツを抽出する強力でカスタムな機能を備えており、操作を高速化し、トークン使用量を最小限に抑えることでコストを削減します。([デモビデオ](https://www.youtube.com/watch?v=qyFk3ZNwOxE))
|
||||
- 🔍 **類似要素の検出**:見つかった要素に類似した要素を自動的に特定。
|
||||
- 🤖 **AIと使用するMCPサーバー**:AI支援Web Scrapingとデータ抽出のための組み込みMCPサーバー。MCPサーバーは、AI(Claude/Cursorなど)に渡す前にScraplingを活用してターゲットコンテンツを抽出する強力でカスタムな機能を備えており、操作を高速化し、トークン使用量を最小限に抑えることでコストを削減します。([デモ動画](https://www.youtube.com/watch?v=qyFk3ZNwOxE))
|
||||
|
||||
### 高性能で実戦テスト済みのアーキテクチャ
|
||||
- 🚀 **高速**:ほとんどのPythonスクレイピングライブラリを上回る最適化されたパフォーマンス。
|
||||
- 🚀 **超高速**:ほとんどのPythonスクレイピングライブラリを上回る最適化されたパフォーマンス。
|
||||
- 🔋 **メモリ効率**:最小のメモリフットプリントのための最適化されたデータ構造と遅延読み込み。
|
||||
- ⚡ **高速JSONシリアル化**:標準ライブラリの10倍の速度。
|
||||
- 🏗️ **実戦テスト済み**:Scraplingは92%のテストカバレッジと完全な型ヒントカバレッジを備えているだけでなく、過去1年間に数百人のウェブスクレイパーによって毎日使用されてきました。
|
||||
- 🏗️ **実戦テスト済み**:Scraplingは92%のテストカバレッジと完全な型ヒントカバレッジを備えているだけでなく、過去1年間に数百人のWeb Scraperによって毎日使用されてきました。
|
||||
|
||||
### 開発者/ウェブスクレイパーにやさしい体験
|
||||
- 🎯 **インタラクティブウェブスクレイピングシェル**:Scraping統合、ショートカット、curlリクエストをScraplingリクエストに変換したり、ブラウザでリクエスト結果を表示したりするなどの新しいツールを備えたオプションの組み込みIPythonシェルで、ウェブスクレイピングスクリプトの開発を加速します。
|
||||
### 開発者/Web Scraperにやさしい体験
|
||||
- 🎯 **インタラクティブWeb Scraping Shell**:Scrapling統合、ショートカット、curlリクエストをScraplingリクエストに変換したり、ブラウザでリクエスト結果を表示したりするなどの新しいツールを備えたオプションの組み込みIPython Shellで、Web Scrapingスクリプトの開発を加速。
|
||||
- 🚀 **ターミナルから直接使用**:オプションで、コードを一行も書かずにScraplingを使用してURLをスクレイプできます!
|
||||
- 🛠️ **豊富なナビゲーションAPI**:親、兄弟、子のナビゲーションメソッドによる高度なDOMトラバーサル。
|
||||
- 🧬 **強化されたテキスト処理**:組み込みの正規表現、クリーニングメソッド、最適化された文字列操作。
|
||||
- 📝 **自動セレクタ生成**:任意の要素に対して堅牢なCSS/XPathセレクタを生成。
|
||||
- 🔌 **馴染みのあるAPI**:Scrapy/Parselで使用されている同じ疑似要素を持つScrapy/BeautifulSoupに似ています。
|
||||
- 📘 **完全な型カバレッジ**:優れたIDEサポートとコード補完のための完全な型ヒント。
|
||||
- 🔌 **馴染みのあるAPI**:Scrapy/Parselで使用されている同じ疑似要素を持つScrapy/BeautifulSoupに似た設計。
|
||||
- 📘 **完全な型カバレッジ**:優れたIDEサポートとコード補完のための完全な型ヒント。コードベース全体が変更のたびに**PyRight**と**MyPy**で自動的にスキャンされます。
|
||||
- 🔋 **すぐに使えるDockerイメージ**:各リリースで、すべてのブラウザを含むDockerイメージが自動的にビルドおよびプッシュされます。
|
||||
|
||||
## はじめに
|
||||
|
||||
### 基本的な使い方
|
||||
```python
|
||||
from scrapling.fetchers import Fetcher, StealthyFetcher, DynamicFetcher
|
||||
from scrapling.fetchers import FetcherSession, StealthySession, DynamicSession
|
||||
深く掘り下げずに、Scraplingにできることの簡単な概要をお見せしましょう。
|
||||
|
||||
# セッションサポート付きHTTPリクエスト
|
||||
with FetcherSession(impersonate='chrome') as session: # ChromeのTLSフィンガープリントの最新バージョンを使用
|
||||
### 基本的な使い方
|
||||
Sessionサポート付きHTTPリクエスト
|
||||
```python
|
||||
from scrapling.fetchers import Fetcher, FetcherSession
|
||||
|
||||
with FetcherSession(impersonate='chrome') as session: # ChromeのTLS fingerprintの最新バージョンを使用
|
||||
page = session.get('https://quotes.toscrape.com/', stealthy_headers=True)
|
||||
quotes = page.css('.quote .text::text')
|
||||
quotes = page.css('.quote .text::text').getall()
|
||||
|
||||
# または一回限りのリクエストを使用
|
||||
page = Fetcher.get('https://quotes.toscrape.com/')
|
||||
quotes = page.css('.quote .text::text')
|
||||
quotes = page.css('.quote .text::text').getall()
|
||||
```
|
||||
高度なステルスモード
|
||||
```python
|
||||
from scrapling.fetchers import StealthyFetcher, StealthySession
|
||||
|
||||
# 高度なステルスモード(完了するまでブラウザを開いたままにする)
|
||||
with StealthySession(headless=True, solve_cloudflare=True) as session:
|
||||
with StealthySession(headless=True, solve_cloudflare=True) as session: # 完了するまでブラウザを開いたままにする
|
||||
page = session.fetch('https://nopecha.com/demo/cloudflare', google_search=False)
|
||||
data = page.css('#padded_content a')
|
||||
data = page.css('#padded_content a').getall()
|
||||
|
||||
# または一回限りのリクエストスタイルを使用、このリクエストのためにブラウザを開き、完了後に閉じる
|
||||
# または一回限りのリクエストスタイル、このリクエストのためにブラウザを開き、完了後に閉じる
|
||||
page = StealthyFetcher.fetch('https://nopecha.com/demo/cloudflare')
|
||||
data = page.css('#padded_content a')
|
||||
|
||||
# 完全なブラウザ自動化(完了するまでブラウザを開いたままにする)
|
||||
with DynamicSession(headless=True) as session:
|
||||
page = session.fetch('https://quotes.toscrape.com/', network_idle=True)
|
||||
quotes = page.css('.quote .text::text')
|
||||
data = page.css('#padded_content a').getall()
|
||||
```
|
||||
完全なブラウザ自動化
|
||||
```python
|
||||
from scrapling.fetchers import DynamicFetcher, DynamicSession
|
||||
|
||||
# または一回限りのリクエストスタイルを使用
|
||||
page = DynamicFetcher.fetch('https://quotes.toscrape.com/', network_idle=True)
|
||||
quotes = page.css('.quote .text::text')
|
||||
with DynamicSession(headless=True, disable_resources=False, network_idle=True) as session: # 完了するまでブラウザを開いたままにする
|
||||
page = session.fetch('https://quotes.toscrape.com/', load_dom=False)
|
||||
data = page.xpath('//span[@class="text"]/text()').getall() # お好みであればXPathセレクタを使用
|
||||
|
||||
# または一回限りのリクエストスタイル、このリクエストのためにブラウザを開き、完了後に閉じる
|
||||
page = DynamicFetcher.fetch('https://quotes.toscrape.com/')
|
||||
data = page.css('.quote .text::text').getall()
|
||||
```
|
||||
|
||||
### 要素の選択
|
||||
### Spider
|
||||
並行リクエスト、複数のSessionタイプ、Pause & Resumeを備えた本格的なクローラーを構築:
|
||||
```python
|
||||
# CSSセレクタ
|
||||
page.css('a::text') # テキストを抽出
|
||||
page.css('a::attr(href)') # 属性を抽出
|
||||
page.css('a', recursive=False) # 直接の要素のみ
|
||||
page.css('a', auto_save=True) # 要素の位置を自動保存
|
||||
from scrapling.spiders import Spider, Request, Response
|
||||
|
||||
# XPath
|
||||
page.xpath('//a/text()')
|
||||
class QuotesSpider(Spider):
|
||||
name = "quotes"
|
||||
start_urls = ["https://quotes.toscrape.com/"]
|
||||
concurrent_requests = 10
|
||||
|
||||
# 柔軟な検索
|
||||
page.find_by_text('Python', first_match=True) # テキストで検索
|
||||
page.find_by_regex(r'\d{4}') # 正規表現パターンで検索
|
||||
page.find('div', {'class': 'container'}) # 属性で検索
|
||||
async def parse(self, response: Response):
|
||||
for quote in response.css('.quote'):
|
||||
yield {
|
||||
"text": quote.css('.text::text').get(),
|
||||
"author": quote.css('.author::text').get(),
|
||||
}
|
||||
|
||||
# ナビゲーション
|
||||
element.parent # 親要素を取得
|
||||
element.next_sibling # 次の兄弟を取得
|
||||
element.children # 子要素を取得
|
||||
next_page = response.css('.next a')
|
||||
if next_page:
|
||||
yield response.follow(next_page[0].attrib['href'])
|
||||
|
||||
# 類似要素
|
||||
similar = page.get_similar(element) # 類似要素を見つける
|
||||
|
||||
# 適応型スクレイピング
|
||||
saved_elements = page.css('.product', auto_save=True)
|
||||
# 後でウェブサイトが変更されたとき:
|
||||
page.css('.product', adaptive=True) # 保存された位置を使用して要素を見つける
|
||||
result = QuotesSpider().start()
|
||||
print(f"{len(result.items)}件の引用をスクレイプしました")
|
||||
result.items.to_json("quotes.json")
|
||||
```
|
||||
|
||||
### セッションの使用
|
||||
単一のSpiderで複数のSessionタイプを使用:
|
||||
```python
|
||||
from scrapling.fetchers import FetcherSession, AsyncFetcherSession
|
||||
from scrapling.spiders import Spider, Request, Response
|
||||
from scrapling.fetchers import FetcherSession, AsyncStealthySession
|
||||
|
||||
# 同期セッション
|
||||
with FetcherSession() as session:
|
||||
# Cookieは自動的に維持されます
|
||||
page1 = session.get('https://quotes.toscrape.com/login')
|
||||
page2 = session.post('https://quotes.toscrape.com/login', data={'username': 'admin', 'password': 'admin'})
|
||||
|
||||
# 必要に応じてブラウザのフィンガープリントを切り替え
|
||||
class MultiSessionSpider(Spider):
|
||||
name = "multi"
|
||||
start_urls = ["https://example.com/"]
|
||||
|
||||
def configure_sessions(self, manager):
|
||||
manager.add("fast", FetcherSession(impersonate="chrome"))
|
||||
manager.add("stealth", AsyncStealthySession(headless=True), lazy=True)
|
||||
|
||||
async def parse(self, response: Response):
|
||||
for link in response.css('a::attr(href)').getall():
|
||||
# 保護されたページはステルスSessionを通してルーティング
|
||||
if "protected" in link:
|
||||
yield Request(link, sid="stealth")
|
||||
else:
|
||||
yield Request(link, sid="fast", callback=self.parse) # 明示的なcallback
|
||||
```
|
||||
Checkpointを使用して長時間のクロールをPause & Resume:
|
||||
```python
|
||||
QuotesSpider(crawldir="./crawl_data").start()
|
||||
```
|
||||
Ctrl+Cを押すと正常に一時停止し、進捗は自動的に保存されます。後でSpiderを再度起動する際に同じ`crawldir`を渡すと、中断したところから再開します。
|
||||
|
||||
### 高度なパースとナビゲーション
|
||||
```python
|
||||
from scrapling.fetchers import Fetcher
|
||||
|
||||
# 豊富な要素選択とナビゲーション
|
||||
page = Fetcher.get('https://quotes.toscrape.com/')
|
||||
|
||||
# 複数の選択メソッドで引用を取得
|
||||
quotes = page.css('.quote') # CSSセレクタ
|
||||
quotes = page.xpath('//div[@class="quote"]') # XPath
|
||||
quotes = page.find_all('div', {'class': 'quote'}) # BeautifulSoupスタイル
|
||||
# 以下と同じ
|
||||
quotes = page.find_all('div', class_='quote')
|
||||
quotes = page.find_all(['div'], class_='quote')
|
||||
quotes = page.find_all(class_='quote') # など...
|
||||
# テキスト内容で要素を検索
|
||||
quotes = page.find_by_text('quote', tag='div')
|
||||
|
||||
# 高度なナビゲーション
|
||||
quote_text = page.css('.quote')[0].css('.text::text').get()
|
||||
quote_text = page.css('.quote').css('.text::text').getall() # チェーンセレクタ
|
||||
first_quote = page.css('.quote')[0]
|
||||
author = first_quote.next_sibling.css('.author::text')
|
||||
parent_container = first_quote.parent
|
||||
|
||||
# 要素の関連性と類似性
|
||||
similar_elements = first_quote.find_similar()
|
||||
below_elements = first_quote.below_elements()
|
||||
```
|
||||
ウェブサイトを取得せずにパーサーをすぐに使用することもできます:
|
||||
```python
|
||||
from scrapling.parser import Selector
|
||||
|
||||
page = Selector("<html>...</html>")
|
||||
```
|
||||
まったく同じ方法で動作します!
|
||||
|
||||
### 非同期Session管理の例
|
||||
```python
|
||||
import asyncio
|
||||
from scrapling.fetchers import FetcherSession, AsyncStealthySession, AsyncDynamicSession
|
||||
|
||||
async with FetcherSession(http3=True) as session: # `FetcherSession`はコンテキストアウェアで、同期/非同期両方のパターンで動作可能
|
||||
page1 = session.get('https://quotes.toscrape.com/')
|
||||
page2 = session.get('https://quotes.toscrape.com/', impersonate='firefox135')
|
||||
|
||||
# 非同期セッションの使用
|
||||
# 非同期Sessionの使用
|
||||
async with AsyncStealthySession(max_pages=2) as session:
|
||||
tasks = []
|
||||
urls = ['https://example.com/page1', 'https://example.com/page2']
|
||||
|
||||
|
||||
for url in urls:
|
||||
task = session.fetch(url)
|
||||
tasks.append(task)
|
||||
|
||||
|
||||
print(session.get_pool_stats()) # オプション - ブラウザタブプールのステータス(ビジー/フリー/エラー)
|
||||
results = await asyncio.gather(*tasks)
|
||||
print(session.get_pool_stats())
|
||||
```
|
||||
|
||||
## CLIとインタラクティブシェル
|
||||
## CLIとインタラクティブShell
|
||||
|
||||
Scrapling v0.3には強力なコマンドラインインターフェースが含まれています:
|
||||
Scraplingには強力なコマンドラインインターフェースが含まれています:
|
||||
|
||||
[](https://asciinema.org/a/736339)
|
||||
|
||||
インタラクティブウェブスクレイピングシェルを起動
|
||||
インタラクティブWeb Scraping Shellを起動
|
||||
```bash
|
||||
scrapling shell
|
||||
```
|
||||
プログラミングせずに直接ページをファイルに抽出(デフォルトで`body`タグ内のコンテンツを抽出)。出力ファイルが`.txt`で終わる場合、ターゲットのテキストコンテンツが抽出されます。`.md`で終わる場合、HTMLコンテンツのMarkdown表現になります;`.html`で終わる場合、HTMLコンテンツそのものになります。
|
||||
プログラミングせずに直接ページをファイルに抽出(デフォルトで`body`タグ内のコンテンツを抽出)。出力ファイルが`.txt`で終わる場合、ターゲットのテキストコンテンツが抽出されます。`.md`で終わる場合、HTMLコンテンツのMarkdown表現になります。`.html`で終わる場合、HTMLコンテンツそのものになります。
|
||||
```bash
|
||||
scrapling extract get 'https://example.com' content.md
|
||||
scrapling extract get 'https://example.com' content.txt --css-selector '#fromSkipToProducts' --impersonate 'chrome' # CSSセレクタ'#fromSkipToProducts'に一致するすべての要素
|
||||
@@ -231,34 +306,34 @@ scrapling extract stealthy-fetch 'https://nopecha.com/demo/cloudflare' captchas.
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> MCPサーバーやインタラクティブウェブスクレイピングシェルなど、他にも多くの追加機能がありますが、このページは簡潔に保ちたいと思います。完全なドキュメントは[こちら](https://scrapling.readthedocs.io/en/latest/)をご覧ください
|
||||
> MCPサーバーやインタラクティブWeb Scraping Shellなど、他にも多くの追加機能がありますが、このページは簡潔に保ちたいと思います。完全なドキュメントは[こちら](https://scrapling.readthedocs.io/en/latest/)をご覧ください
|
||||
|
||||
## パフォーマンスベンチマーク
|
||||
|
||||
Scraplingは強力であるだけでなく、驚くほど高速で、バージョン0.3以降のアップデートはすべての操作で優れたパフォーマンス向上を実現しています。以下のベンチマークは、Scraplingのパーサーを他の人気のあるライブラリと比較しています。
|
||||
Scraplingは強力であるだけでなく、超高速です。以下のベンチマークは、Scraplingのパーサーを他の人気ライブラリの最新バージョンと比較しています。
|
||||
|
||||
### テキスト抽出速度テスト(5000個のネストされた要素)
|
||||
|
||||
| # | ライブラリ | 時間(ms) | vs Scrapling |
|
||||
|---|:-----------------:|:-------:|:------------:|
|
||||
| 1 | Scrapling | 1.99 | 1.0x |
|
||||
| 2 | Parsel/Scrapy | 2.01 | 1.01x |
|
||||
| 3 | Raw Lxml | 2.5 | 1.256x |
|
||||
| 4 | PyQuery | 22.93 | ~11.5x |
|
||||
| 5 | Selectolax | 80.57 | ~40.5x |
|
||||
| 6 | BS4 with Lxml | 1541.37 | ~774.6x |
|
||||
| 7 | MechanicalSoup | 1547.35 | ~777.6x |
|
||||
| 8 | BS4 with html5lib | 3410.58 | ~1713.9x |
|
||||
| # | ライブラリ | 時間(ms) | vs Scrapling |
|
||||
|---|:-----------------:|:---------:|:------------:|
|
||||
| 1 | Scrapling | 2.02 | 1.0x |
|
||||
| 2 | Parsel/Scrapy | 2.04 | 1.01 |
|
||||
| 3 | Raw Lxml | 2.54 | 1.257 |
|
||||
| 4 | PyQuery | 24.17 | ~12x |
|
||||
| 5 | Selectolax | 82.63 | ~41x |
|
||||
| 6 | MechanicalSoup | 1549.71 | ~767.1x |
|
||||
| 7 | BS4 with Lxml | 1584.31 | ~784.3x |
|
||||
| 8 | BS4 with html5lib | 3391.91 | ~1679.1x |
|
||||
|
||||
|
||||
### 要素類似性とテキスト検索のパフォーマンス
|
||||
|
||||
Scraplingの適応型要素検索機能は代替手段を大幅に上回ります:
|
||||
|
||||
| ライブラリ | 時間(ms) | vs Scrapling |
|
||||
|-------------|:------:|:------------:|
|
||||
| Scrapling | 2.46 | 1.0x |
|
||||
| AutoScraper | 13.3 | 5.407x |
|
||||
| ライブラリ | 時間(ms) | vs Scrapling |
|
||||
|-------------|:---------:|:------------:|
|
||||
| Scrapling | 2.39 | 1.0x |
|
||||
| AutoScraper | 12.45 | 5.209x |
|
||||
|
||||
|
||||
> すべてのベンチマークは100回以上の実行の平均を表します。方法論については[benchmarks.py](https://github.com/D4Vinci/Scrapling/blob/main/benchmarks.py)を参照してください。
|
||||
@@ -271,25 +346,25 @@ ScraplingにはPython 3.10以上が必要です:
|
||||
pip install scrapling
|
||||
```
|
||||
|
||||
v0.3.2以降、このインストールにはパーサーエンジンとその依存関係のみが含まれており、フェッチャーやコマンドライン依存関係は含まれていません。
|
||||
このインストールにはパーサーエンジンとその依存関係のみが含まれており、Fetcherやコマンドライン依存関係は含まれていません。
|
||||
|
||||
### オプションの依存関係
|
||||
|
||||
1. 以下の追加機能、フェッチャー、またはそれらのクラスのいずれかを使用する場合は、フェッチャーの依存関係とブラウザの依存関係を次のようにインストールする必要があります:
|
||||
1. 以下の追加機能、Fetcher、またはそれらのクラスのいずれかを使用する場合は、Fetcherの依存関係とブラウザの依存関係を次のようにインストールする必要があります:
|
||||
```bash
|
||||
pip install "scrapling[fetchers]"
|
||||
|
||||
|
||||
scrapling install
|
||||
```
|
||||
|
||||
これにより、すべてのブラウザ、およびそれらのシステム依存関係とフィンガープリント操作依存関係がダウンロードされます。
|
||||
これにより、すべてのブラウザ、およびそれらのシステム依存関係とfingerprint操作依存関係がダウンロードされます。
|
||||
|
||||
2. 追加機能:
|
||||
- MCPサーバー機能をインストール:
|
||||
```bash
|
||||
pip install "scrapling[ai]"
|
||||
```
|
||||
- シェル機能(ウェブスクレイピングシェルと`extract`コマンド)をインストール:
|
||||
- Shell機能(Web Scraping Shellと`extract`コマンド)をインストール:
|
||||
```bash
|
||||
pip install "scrapling[shell]"
|
||||
```
|
||||
@@ -328,12 +403,5 @@ docker pull ghcr.io/d4vinci/scrapling:latest
|
||||
このプロジェクトには次から適応されたコードが含まれています:
|
||||
- Parsel(BSDライセンス)— [translator](https://github.com/D4Vinci/Scrapling/blob/main/scrapling/core/translator.py)サブモジュールに使用
|
||||
|
||||
## 感謝と参考文献
|
||||
|
||||
- [Daijro](https://github.com/daijro)の[BrowserForge](https://github.com/daijro/browserforge)と[Camoufox](https://github.com/daijro/camoufox)における素晴らしい仕事
|
||||
- [Vinyzu](https://github.com/Vinyzu)の[Botright](https://github.com/Vinyzu/Botright)と[PatchRight](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)における素晴らしい仕事
|
||||
- ブラウザ検出回避技術を提供する[brotector](https://github.com/kaliiiiiiiiii/brotector)
|
||||
- フィンガープリント研究を提供する[fakebrowser](https://github.com/kkoooqq/fakebrowser)と[BotBrowser](https://github.com/botswin/BotBrowser)
|
||||
|
||||
---
|
||||
<div align="center"><small>Karim Shoairによって❤️でデザインおよび作成されました。</small></div><br>
|
||||
<div align="center"><small>Karim Shoairによって❤️でデザインおよび作成されました。</small></div><br>
|
||||
|
||||
Reference in New Issue
Block a user