Code Monkey home page Code Monkey logo

simple_scraper's Introduction

再帰的ウェブスクレイピングスクリプト

このスクリプトは、指定されたドメイン内のウェブサイトを再帰的にスクレイピングします。特定のURLから開始し、そのページにある全てのリンクをたどり、リンク先のページも同様にスクレイピングします。

使用方法

  1. start_url にスクレイピングを開始するURLを設定します。
  2. target_domain にスクレイピング対象のドメインを設定します。
  3. max_depth にリンクをたどる最大の深さを設定します。
  4. スクリプトを実行すると、指定されたドメイン内のページから requests.Response オブジェクトが順に返されます。

コード例

start_url = "https://example.com"  # スクレイピングを開始するURL
target_domain = "example.com"  # スクレイピング対象のドメイン
for response in scrape_site_generator(start_url, target_domain, set(), 2):
    # ここで各responseを処理する
    print(f"Got response from {response.url}")

要件

  • Python 3
  • BeautifulSoup4
  • requests

注意事項

  • スクレイピングする際は、対象ウェブサイトの利用規約を遵守してください。
  • サーバーに過度な負荷をかけないように注意し、適切な速度制限を設定してください。
  • robots.txt を確認し、ウェブサイトのスクレイピングポリシーに従ってください。

余談

余談以外全部GPT4で作りました😛

simple_scraper's People

Contributors

hawkclaws avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.