File size: 32,617 Bytes
0c156aa
 
10bebe8
 
 
28706dc
 
10bebe8
 
 
5e95d8a
10bebe8
5e95d8a
05f479b
 
 
 
 
00be88a
03d3c9b
 
 
 
05f479b
 
 
 
 
 
 
 
 
 
 
 
 
062168a
5e95d8a
d816dbf
5e95d8a
06c609b
 
 
 
062168a
5e95d8a
d816dbf
05f479b
 
d816dbf
05f479b
d816dbf
05f479b
d816dbf
05f479b
 
5e95d8a
 
19df43f
 
 
05f479b
5e95d8a
 
 
 
 
 
 
05f479b
5e95d8a
 
 
 
 
 
 
38cd335
 
 
 
 
5e95d8a
0c156aa
e867c7f
 
1f8449d
e867c7f
 
4ab9cde
 
d816dbf
6492340
d816dbf
e867c7f
808845d
1f8449d
808845d
 
 
 
6492340
 
 
d816dbf
808845d
 
4ab9cde
1f8449d
4ab9cde
 
 
 
6492340
 
 
 
4ab9cde
6b802e7
 
 
 
 
 
4ab9cde
 
6b802e7
 
 
4ab9cde
4bc3405
 
 
 
 
 
 
587c648
4bc3405
 
910837a
 
 
 
 
 
 
 
d816dbf
910837a
 
da9a509
 
 
 
 
 
 
d816dbf
da9a509
 
78e069b
 
 
 
 
 
 
 
 
 
e867c7f
 
 
5e95d8a
05f479b
 
 
0136fff
05f479b
0690d65
e0c2f93
a0dfed9
66b9e49
05f479b
 
 
 
 
 
 
 
 
5e95d8a
d816dbf
5e95d8a
d816dbf
 
 
5e95d8a
d816dbf
 
 
 
 
 
 
 
 
 
 
 
05f479b
d816dbf
5e95d8a
d816dbf
05f479b
 
d816dbf
05f479b
d816dbf
 
05f479b
d816dbf
 
 
 
05f479b
d816dbf
 
 
 
05f479b
 
 
d816dbf
5e95d8a
05f479b
d816dbf
05f479b
5e95d8a
05f479b
d816dbf
05f479b
5e95d8a
05f479b
 
 
5e95d8a
 
 
 
 
05f479b
5e95d8a
05f479b
5e95d8a
05f479b
5e95d8a
05f479b
5e95d8a
 
 
 
 
 
 
 
d816dbf
5e95d8a
 
 
 
05f479b
 
5e95d8a
d816dbf
05f479b
5e95d8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05f479b
d816dbf
5e95d8a
 
 
 
 
 
 
 
 
 
 
 
 
 
d816dbf
5e95d8a
 
 
d816dbf
5e95d8a
d816dbf
5e95d8a
 
 
d816dbf
5e95d8a
 
 
 
 
 
 
05f479b
5e95d8a
d816dbf
5e95d8a
d816dbf
5e95d8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05f479b
5e95d8a
 
 
 
 
 
d816dbf
5e95d8a
 
 
 
d816dbf
5e95d8a
05f479b
 
d816dbf
05f479b
 
 
5e95d8a
05f479b
 
 
5e95d8a
05f479b
 
 
 
 
d816dbf
05f479b
d816dbf
05f479b
 
 
d816dbf
05f479b
 
e85bf1f
d816dbf
e85bf1f
05f479b
d816dbf
05f479b
 
 
 
 
d816dbf
05f479b
 
 
d816dbf
05f479b
d816dbf
05f479b
d816dbf
5e95d8a
 
 
 
 
 
 
 
 
e0b5a75
05f479b
 
 
d816dbf
05f479b
d816dbf
5e95d8a
 
 
05f479b
 
d816dbf
05f479b
 
 
d816dbf
05f479b
 
 
 
 
d816dbf
05f479b
 
 
d816dbf
05f479b
 
5e95d8a
1b37b00
 
05f479b
 
d816dbf
05f479b
1b37b00
 
 
 
 
 
 
 
05f479b
d816dbf
05f479b
 
 
d816dbf
05f479b
 
 
 
 
 
 
 
 
 
d816dbf
05f479b
 
 
d816dbf
05f479b
 
 
d816dbf
05f479b
 
 
 
 
 
 
 
d816dbf
05f479b
4d91a34
 
 
 
 
 
 
 
 
 
 
 
05f479b
 
d816dbf
05f479b
 
 
 
d816dbf
05f479b
 
d816dbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<!-- mcp-name: io.github.D4Vinci/Scrapling -->

<h1 align="center">
    <a href="https://scrapling.readthedocs.io">
        <picture>
          <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/docs/assets/cover_dark.svg?sanitize=true">
          <img alt="Scrapling Poster" src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/docs/assets/cover_light.svg?sanitize=true">
        </picture>
    </a>
    <br>
    <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>
    <a href="https://badge.fury.io/py/Scrapling" alt="PyPI version">
        <img alt="PyPI version" src="https://badge.fury.io/py/Scrapling.svg"></a>
    <a href="https://clickpy.clickhouse.com/dashboard/scrapling" rel="nofollow"><img src="https://img.shields.io/pypi/dm/scrapling" alt="PyPI package downloads"></a>
    <a href="https://github.com/D4Vinci/Scrapling/tree/main/agent-skill" alt="AI Agent Skill directory">
        <img alt="Static Badge" src="https://img.shields.io/badge/Skill-black?style=flat&label=Agent&link=https%3A%2F%2Fgithub.com%2FD4Vinci%2FScrapling%2Ftree%2Fmain%2Fagent-skill"></a>
    <a href="https://clawhub.ai/D4Vinci/scrapling-official" alt="OpenClaw Skill">
        <img alt="OpenClaw Skill" src="https://img.shields.io/badge/Clawhub-darkred?style=flat&label=OpenClaw&link=https%3A%2F%2Fclawhub.ai%2FD4Vinci%2Fscrapling-official"></a>
    <br/>
    <a href="https://discord.gg/EMgGbDceNQ" alt="Discord" target="_blank">
      <img alt="Discord" src="https://img.shields.io/discord/1360786381042880532?style=social&logo=discord&link=https%3A%2F%2Fdiscord.gg%2FEMgGbDceNQ">
    </a>
    <a href="https://x.com/Scrapling_dev" alt="X (formerly Twitter)">
      <img alt="X (formerly Twitter) Follow" src="https://img.shields.io/twitter/follow/Scrapling_dev?style=social&logo=x&link=https%3A%2F%2Fx.com%2FScrapling_dev">
    </a>
    <br/>
    <a href="https://pypi.org/project/scrapling/" alt="Supported Python versions">
        <img alt="Supported Python versions" src="https://img.shields.io/pypi/pyversions/scrapling.svg"></a>
</p>

<p align="center">
    <a href="https://scrapling.readthedocs.io/en/latest/parsing/selection.html"><strong>遞択メ゜ッド</strong></a>
    &middot;
    <a href="https://scrapling.readthedocs.io/en/latest/fetching/choosing.html"><strong>Fetcher の遞び方</strong></a>
    &middot;
    <a href="https://scrapling.readthedocs.io/en/latest/spiders/architecture.html"><strong>スパむダヌ</strong></a>
    &middot;
    <a href="https://scrapling.readthedocs.io/en/latest/spiders/proxy-blocking.html"><strong>プロキシロヌテヌション</strong></a>
    &middot;
    <a href="https://scrapling.readthedocs.io/en/latest/cli/overview.html"><strong>CLI</strong></a>
    &middot;
    <a href="https://scrapling.readthedocs.io/en/latest/ai/mcp-server.html"><strong>MCP モヌド</strong></a>
</p>

Scrapling は、単䞀のリク゚ストから本栌的なクロヌルたですべおを凊理する適応型 Web Scraping フレヌムワヌクです。

そのパヌサヌはりェブサむトの倉曎から孊習し、ペヌゞが曎新されたずきに芁玠を自動的に再配眮したす。Fetcher はすぐに䜿える Cloudflare Turnstile などのアンチボットシステムを回避したす。そしお Spider フレヌムワヌクにより、Pause & Resume や自動 Proxy 回転機胜を備えた䞊行マルチ Session クロヌルぞずスケヌルアップできたす — すべおわずか数行の Python で。1 ぀のラむブラリ、劥協なし。

リアルタむム統蚈ず Streaming による超高速クロヌル。Web Scraper によっお、Web Scraper ず䞀般ナヌザヌのために構築され、誰にでも䜕かがありたす。

```python
from scrapling.fetchers import Fetcher, AsyncFetcher, StealthyFetcher, DynamicFetcher
StealthyFetcher.adaptive = True
p = StealthyFetcher.fetch('https://example.com', headless=True, network_idle=True)  # レヌダヌの䞋でりェブサむトを取埗
products = p.css('.product', auto_save=True)                                        # りェブサむトのデザむン倉曎に耐えるデヌタをスクレむプ
products = p.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()
```

<p align="center">
    <a href="https://dataimpulse.com/?utm_source=scrapling&utm_medium=banner&utm_campaign=scrapling" target="_blank" style="display:flex; justify-content:center; padding:4px 0;">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/DataImpulse.png" alt="At DataImpulse, we specialize in developing custom proxy services for your business. Make requests from anywhere, collect data, and enjoy fast connections with our premium proxies." style="max-height:60px;">
    </a>
</p>

# プラチナスポンサヌ
<table>
  <tr>
    <td width="200">
      <a href="https://hypersolutions.co/?utm_source=github&utm_medium=readme&utm_campaign=scrapling" target="_blank" title="Bot Protection Bypass API for Akamai, DataDome, Incapsula & Kasada">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/HyperSolutions.png">
      </a>
    </td>
    <td> Scrapling は Cloudflare Turnstile に察応。゚ンタヌプラむズレベルの保護には、<a href="https://hypersolutions.co?utm_source=github&utm_medium=readme&utm_campaign=scrapling">
        <b>Hyper Solutions</b>
      </a>が<b>Akamai</b>、<b>DataDome</b>、<b>Kasada</b>、<b>Incapsula</b>向けの有効な antibot トヌクンを生成する API ゚ンドポむントを提䟛。シンプルな API 呌び出しで、ブラりザ自動化䞍芁。 </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://birdproxies.com/t/scrapling" target="_blank" title="At Bird Proxies, we eliminate your pains such as banned IPs, geo restriction, and high costs so you can focus on your work.">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/BirdProxies.jpg">
      </a>
    </td>
    <td>プロキシは耇雑で高䟡であるべきではないず考え、<a href="https://birdproxies.com/t/scrapling">
        <b>BirdProxies</b>
      </a>を構築したした。 <br /> 195以䞊のロケヌションの高速レゞデンシャル・ISPプロキシ、公正な䟡栌蚭定、そしお本物のサポヌト。 <br />
      <b>ランディングペヌゞでFlappyBird ゲヌムを詊しお無料デヌタをゲット</b>
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://evomi.com?utm_source=github&utm_medium=banner&utm_campaign=d4vinci-scrapling" target="_blank" title="Evomi is your Swiss Quality Proxy Provider, starting at $0.49/GB">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/evomi.png">
      </a>
    </td>
    <td>
      <a href="https://evomi.com?utm_source=github&utm_medium=banner&utm_campaign=d4vinci-scrapling">
        <b>Evomi</b>
      </a>レゞデンシャルプロキシが $0.49/GB から。完党に停装された Chromium によるスクレむピングブラりザ、レゞデンシャル IP、自動 CAPTCHA 解決、アンチボットバむパス。</br>
      <b>Scraper API で手間なく結果を取埗。MCP ず N8N の統合に察応。</b>
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://tikhub.io/?ref=KarimShoair" target="_blank" title="Unlock the Power of Social Media Data & AI">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/TikHub.jpg">
      </a>
    </td>
    <td>
      <a href="https://tikhub.io/?ref=KarimShoair" target="_blank">TikHub.io</a> は TikTok、X、YouTube、Instagram を含む 16 以䞊のプラットフォヌムで 900 以䞊の安定した API を提䟛し、4,000 䞇以䞊のデヌタセットを保有。<br /> さらに <a href="https://ai.tikhub.io/?ref=KarimShoair" target="_blank">割匕 AI モデル</a>も提䟛 — Claude、GPT、GEMINI など最倧 71% オフ。
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://www.nsocks.com/?keyword=2p67aivg" target="_blank" title="Scalable Web Data Access for AI Applications">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/nsocks.png">
      </a>
    </td>
    <td>
    <a href="https://www.nsocks.com/?keyword=2p67aivg" target="_blank">Nsocks</a> は開発者やスクレむパヌ向けの高速なレゞデンシャルおよび ISP プロキシを提䟛。グロヌバル IP カバレッゞ、高い匿名性、スマヌトなロヌテヌション、自動化ずデヌタ抜出のための信頌性の高いパフォヌマンス。<a href="https://www.xcrawl.com/?keyword=2p67aivg" target="_blank">Xcrawl</a> で倧芏暡りェブクロヌリングを簡玠化。
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://petrosky.io/d4vinci" target="_blank" title="PetroSky delivers cutting-edge VPS hosting.">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/petrosky.png">
      </a>
    </td>
    <td>
    ノヌトパ゜コンを閉じおも、スクレむパヌは動き続けたす。<br />
    <a href="https://petrosky.io/d4vinci" target="_blank">PetroSky VPS</a> - ノンストップ自動化のために構築されたクラりドサヌバヌ。Windows ず Linux マシンを完党制埡。月額 €6.99 から。
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://substack.thewebscraping.club/p/scrapling-hands-on-guide?utm_source=github&utm_medium=repo&utm_campaign=scrapling" target="_blank" title="The #1 newsletter dedicated to Web Scraping">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/TWSC.png">
      </a>
    </td>
    <td>
    <a href="https://substack.thewebscraping.club/p/scrapling-hands-on-guide?utm_source=github&utm_medium=repo&utm_campaign=scrapling" target="_blank">The Web Scraping Club で Scrapling の詳现レビュヌ</a>2025幎11月をお読みください。Web スクレむピング専門の No.1 ニュヌスレタヌです。
    </td>
  </tr>
  <tr>
    <td width="200">
      <a href="https://proxy-seller.com/?partner=CU9CAA5TBYFFT2" target="_blank" title="Proxy-Seller provides reliable proxy infrastructure for Web Scraping">
        <img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/ProxySeller.png">
      </a>
    </td>
    <td>
    <a href="https://proxy-seller.com/?partner=CU9CAA5TBYFFT2" target="_blank">Proxy-Seller</a> は Web スクレむピング向けの信頌性の高いプロキシむンフラを提䟛しおいたす。IPv4、IPv6、ISP、レゞデンシャル、モバむルプロキシに察応し、安定したパフォヌマンス、幅広い地理的カバレッゞ、䌁業芏暡のデヌタ収集に柔軟なプランを備えおいたす。
    </td>
  </tr>
</table>

<i><sub>ここに広告を衚瀺したいですか[こちら](https://github.com/sponsors/D4Vinci/sponsorships?tier_id=586646)をクリック</sub></i>
# スポンサヌ

<!-- sponsors -->

<a href="https://serpapi.com/?utm_source=scrapling" target="_blank" title="Scrape Google and other search engines with SerpApi"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/SerpApi.png"></a>
<a href="https://visit.decodo.com/Dy6W0b" target="_blank" title="Try the Most Efficient Residential Proxies for Free"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/decodo.png"></a>
<a href="https://hasdata.com/?utm_source=github&utm_medium=banner&utm_campaign=D4Vinci" target="_blank" title="The web scraping service that actually beats anti-bot systems!"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/hasdata.png"></a>
<a href="https://proxyempire.io/?ref=scrapling&utm_source=scrapling" target="_blank" title="Collect The Data Your Project Needs with the Best Residential Proxies"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/ProxyEmpire.png"></a>
<a href="https://www.webshare.io/?referral_code=48r2m2cd5uz1" target="_blank" title="The Most Reliable Proxy with Unparalleled Performance"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/webshare.png"></a>
<a href="https://browser.cash/?utm_source=D4Vinci&utm_medium=referral" target="_blank" title="Browser Automation & AI Browser Agent Platform"><img src="https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/browserCash.png"></a>

<!-- /sponsors -->

<i><sub>ここに広告を衚瀺したいですか[こちら](https://github.com/sponsors/D4Vinci)をクリックしお、あなたに合ったティアを遞択しおください</sub></i>

---

## 䞻な機胜

### 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 および専甚 async Session クラス党䜓での完党な async サポヌト。

### 適応型スクレむピングず AI 統合
- 🔄 **スマヌト芁玠远跡**むンテリゞェントな類䌌性アルゎリズムを䜿甚しおりェブサむトの倉曎埌に芁玠を再配眮。
- 🎯 **スマヌト柔軟遞択**CSS セレクタ、XPath セレクタ、フィルタベヌス怜玢、テキスト怜玢、正芏衚珟怜玢など。
- 🔍 **類䌌芁玠の怜出**芋぀かった芁玠に類䌌した芁玠を自動的に特定。
- 🀖 **AI ず䜿甚する MCP サヌバヌ**AI 支揎 Web Scraping ずデヌタ抜出のための組み蟌み MCP サヌバヌ。MCP サヌバヌは、AIClaude/Cursor などに枡す前に Scrapling を掻甚しおタヌゲットコンテンツを抜出する匷力でカスタムな機胜を備えおおり、操䜜を高速化し、トヌクン䜿甚量を最小限に抑えるこずでコストを削枛したす。[デモ動画](https://www.youtube.com/watch?v=qyFk3ZNwOxE)

### 高性胜で実戊テスト枈みのアヌキテクチャ
- 🚀 **超高速**ほずんどの Python スクレむピングラむブラリを䞊回る最適化されたパフォヌマンス。
- 🔋 **メモリ効率**最小のメモリフットプリントのための最適化されたデヌタ構造ず遅延読み蟌み。
- ⚡ **高速 JSON シリアル化**暙準ラむブラリの 10 倍の速床。
- 🏗 **実戊テスト枈み**Scrapling は 92% のテストカバレッゞず完党な型ヒントカバレッゞを備えおいるだけでなく、過去1幎間に数癟人の Web Scraper によっお毎日䜿甚されおきたした。

### 開発者/Web Scraper にやさしい䜓隓
- 🎯 **むンタラクティブ Web Scraping Shell**Scrapling 統合、ショヌトカット、curl リク゚ストを Scrapling リク゚ストに倉換したり、ブラりザでリク゚スト結果を衚瀺したりするなどの新しいツヌルを備えたオプションの組み蟌み IPython Shell で、Web Scraping スクリプトの開発を加速。
- 🚀 **タヌミナルから盎接䜿甚**オプションで、コヌドを䞀行も曞かずに Scrapling を䜿甚しお URL をスクレむプできたす
- 🛠 **豊富なナビゲヌション API**芪、兄匟、子のナビゲヌションメ゜ッドによる高床な DOM トラバヌサル。
- 🧬 **匷化されたテキスト凊理**組み蟌みの正芏衚珟、クリヌニングメ゜ッド、最適化された文字列操䜜。
- 📝 **自動セレクタ生成**任意の芁玠に察しお堅牢な CSS/XPath セレクタを生成。
- 🔌 **銎染みのある API**Scrapy/Parsel で䜿甚されおいる同じ疑䌌芁玠を持぀ Scrapy/BeautifulSoup に䌌た蚭蚈。
- 📘 **完党な型カバレッゞ**優れた IDE サポヌトずコヌド補完のための完党な型ヒント。コヌドベヌス党䜓が倉曎のたびに**PyRight**ず**MyPy**で自動的にスキャンされたす。
- 🔋 **すぐに䜿える Docker むメヌゞ**各リリヌスで、すべおのブラりザを含む Docker むメヌゞが自動的にビルドおよびプッシュされたす。

## はじめに

深く掘り䞋げずに、Scrapling にできるこずの簡単な抂芁をお芋せしたしょう。

### 基本的な䜿い方
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').getall()

# たたは䞀回限りのリク゚ストを䜿甚
page = Fetcher.get('https://quotes.toscrape.com/')
quotes = page.css('.quote .text::text').getall()
```
高床なステルスモヌド
```python
from scrapling.fetchers import StealthyFetcher, StealthySession

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').getall()

# たたは䞀回限りのリク゚ストスタむル、このリク゚ストのためにブラりザを開き、完了埌に閉じる
page = StealthyFetcher.fetch('https://nopecha.com/demo/cloudflare')
data = page.css('#padded_content a').getall()
```
完党なブラりザ自動化
```python
from scrapling.fetchers import DynamicFetcher, DynamicSession

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
from scrapling.spiders import Spider, Request, Response

class QuotesSpider(Spider):
    name = "quotes"
    start_urls = ["https://quotes.toscrape.com/"]
    concurrent_requests = 10

    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(),
            }

        next_page = response.css('.next a')
        if next_page:
            yield response.follow(next_page[0].attrib['href'])

result = QuotesSpider().start()
print(f"{len(result.items)}件の匕甚をスクレむプしたした")
result.items.to_json("quotes.json")
```
単䞀の Spider で耇数の Session タむプを䜿甚
```python
from scrapling.spiders import Spider, Request, Response
from scrapling.fetchers import FetcherSession, AsyncStealthySession

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 ずむンタラクティブ Shell

Scrapling には匷力なコマンドラむンむンタヌフェヌスが含たれおいたす

[![asciicast](https://asciinema.org/a/736339.svg)](https://asciinema.org/a/736339)

むンタラクティブ Web Scraping Shell を起動
```bash
scrapling shell
```
プログラミングせずに盎接ペヌゞをファむルに抜出デフォルトで`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'に䞀臎するすべおの芁玠
scrapling extract fetch 'https://example.com' content.md --css-selector '#fromSkipToProducts' --no-headless
scrapling extract stealthy-fetch 'https://nopecha.com/demo/cloudflare' captchas.html --css-selector '#padded_content a' --solve-cloudflare
```

> [!NOTE]
> MCP サヌバヌやむンタラクティブ Web Scraping Shell など、他にも倚くの远加機胜がありたすが、このペヌゞは簡朔に保ちたいず思いたす。完党なドキュメントは[こちら](https://scrapling.readthedocs.io/en/latest/)をご芧ください

## パフォヌマンスベンチマヌク

Scrapling は匷力であるだけでなく、超高速です。以䞋のベンチマヌクは、Scrapling のパヌサヌを他の人気ラむブラリの最新バヌゞョンず比范しおいたす。

### テキスト抜出速床テスト5000 個のネストされた芁玠

| # |      ラむブラリ      | 時間 (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.39    |     1.0x     |
| AutoScraper |   12.45   |    5.209x    |


> すべおのベンチマヌクは 100 回以䞊の実行の平均を衚したす。方法論に぀いおは[benchmarks.py](https://github.com/D4Vinci/Scrapling/blob/main/benchmarks.py)を参照しおください。

## むンストヌル

Scrapling には Python 3.10 以䞊が必芁です

```bash
pip install scrapling
```

このむンストヌルにはパヌサヌ゚ンゞンずその䟝存関係のみが含たれおおり、Fetcher やコマンドラむン䟝存関係は含たれおいたせん。

### オプションの䟝存関係

1. 以䞋の远加機胜、Fetcher、たたはそれらのクラスのいずれかを䜿甚する堎合は、Fetcher の䟝存関係ずブラりザの䟝存関係を次のようにむンストヌルする必芁がありたす
    ```bash
    pip install "scrapling[fetchers]"

    scrapling install           # normal install
    scrapling install  --force  # force reinstall
    ```

    これにより、すべおのブラりザ、およびそれらのシステム䟝存関係ずfingerprint 操䜜䟝存関係がダりンロヌドされたす。

    たたは、コマンドを実行する代わりにコヌドからむンストヌルするこずもできたす
    ```python
    from scrapling.cli import install

    install([], standalone_mode=False)          # normal install
    install(["--force"], standalone_mode=False) # force reinstall
    ```

2. 远加機胜
   - MCP サヌバヌ機胜をむンストヌル
       ```bash
       pip install "scrapling[ai]"
       ```
   - Shell 機胜Web Scraping Shell ず`extract`コマンドをむンストヌル
       ```bash
       pip install "scrapling[shell]"
       ```
   - すべおをむンストヌル
       ```bash
       pip install "scrapling[all]"
       ```
   これらの远加機胜のいずれかの埌ただむンストヌルしおいない堎合、`scrapling install`でブラりザの䟝存関係をむンストヌルする必芁があるこずを忘れないでください

### Docker
DockerHub から次のコマンドですべおの远加機胜ずブラりザを含む Docker むメヌゞをむンストヌルするこずもできたす
```bash
docker pull pyd4vinci/scrapling
```
たたは GitHub レゞストリからダりンロヌド
```bash
docker pull ghcr.io/d4vinci/scrapling:latest
```
このむメヌゞは、GitHub Actions ずリポゞトリのメむンブランチを䜿甚しお自動的にビルドおよびプッシュされたす。

## 貢献

貢献を歓迎したす始める前に[貢献ガむドラむン](https://github.com/D4Vinci/Scrapling/blob/main/CONTRIBUTING.md)をお読みください。

## 免責事項

> [!CAUTION]
> このラむブラリは教育および研究目的のみで提䟛されおいたす。このラむブラリを䜿甚するこずにより、地域および囜際的なデヌタスクレむピングおよびプラむバシヌ法に準拠するこずに同意したものずみなされたす。著者および貢献者は、この゜フトりェアの誀甚に぀いお責任を負いたせん。垞にりェブサむトの利甚芏玄ずrobots.txt ファむルを尊重しおください。

## 🎓 匕甚
研究目的で圓ラむブラリを䜿甚された堎合は、以䞋の参考文献で匕甚しおください
```text
  @misc{scrapling,
    author = {Karim Shoair},
    title = {Scrapling},
    year = {2024},
    url = {https://github.com/D4Vinci/Scrapling},
    note = {An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!}
  }
```

## ラむセンス

この䜜品は BSD-3-Clause ラむセンスの䞋でラむセンスされおいたす。

## 謝蟞

このプロゞェクトには次から適応されたコヌドが含たれおいたす
- ParselBSD ラむセンス— [translator](https://github.com/D4Vinci/Scrapling/blob/main/scrapling/core/translator.py) サブモゞュヌルに䜿甚

---
<div align="center"><small>Karim Shoair によっお❀でデザむンおよび䜜成されたした。</small></div><br>