パイソンのためのスマートで、自動で、速くて軽量ウェブスクレイパー


こんにちは皆さん、私はあなたに呼ばれる偉大なスクレーパーを表示したいAutoScraper , クールな名前ではないですか?😃 😃 . スマート、自動、高速、軽量WebスクレイラPythonのためのWebスクレージングを簡単になります.これは、URLまたはWebページのHTMLコンテンツを取得し、サンプルページのリストは、我々はそのページからscrapeする.このデータは、テキスト、URL、またはそのページの任意のHTMLタグの値をすることができます.これは、スクラップルールを学習し、同様の要素を返します.それから、あなたは類似した内容またはこれらの新しいページの同じ要素を得るために、新しいURLでこの学んだオブジェクトを使うことができます.
GIPリポジトリから最新バージョンをインストールします.
$ pip install git+https://github.com/alirezamika/autoscraper.git
pypiからインストールします
pip install autoscraper
ソースからインストール
python setup.py install

使い方

類似結果
すべての関連するタイトルをスタックオーバーフローページで取得したいとします.
from autoscraper import AutoScraper

url = 'https://stackoverflow.com/questions/2081586/web-scraping-with-python'

wanted_list = ["How to call an external command?"]

scraper = AutoScraper()
result = scraper.build(url, wanted_list)
print(result)
出力を以下に示します:
[
    'How do I merge two dictionaries in a single expression in Python (taking union of dictionaries)?', 
    'How to call an external command?', 
    'What are metaclasses in Python?', 
    'Does Python have a ternary conditional operator?', 
    'How do you remove duplicates from a list whilst preserving order?', 
    'Convert bytes to a string', 
    'How to get line count of a large file cheaply in Python?', 
    "Does Python have a string 'contains' substring method?", 
    'Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?'
]
今、あなたはscraper 任意のスタックオーバーページの関連するトピックを取得するオブジェクトです.
scraper.get_result_similar('https://stackoverflow.com/questions/606191/convert-bytes-to-a-string')

正確な結果
ヤフー・ファイナンスから株価を削りたいと言います.
from autoscraper import AutoScraper

url = 'https://finance.yahoo.com/quote/AAPL/'

wanted_list = ["124.81"]

scraper = AutoScraper()

the url (html=html_content)
result = scraper.build(url, wanted_list)
print(result)
更新する必要がありますwanted_list このコードをコピーする場合は、ページの内容が動的に変更されます.
もう一つの例:我々は、テキスト、星の数とGitHubレポページの問題へのリンクについてscrapeしたいと言います:
from autoscraper import AutoScraper

url = 'https://github.com/alirezamika/autoscraper'

wanted_list = ['A Smart, Automatic, Fast and Lightweight Web Scraper for Python', '2.2k', 'https://github.com/alirezamika/autoscraper/issues']

scraper = AutoScraper()
scraper.build(url, wanted_list)
かなり甘いha?

グループ化の結果と不要なものを取り除く
ここでは、eBay製品ページから商品名、価格および評価を削りたいです.
url = 'https://www.ebay.com/itm/Sony-PlayStation-4-PS4-Pro-1TB-4K-Console-Black/203084236670' 

wanted_list = ['Sony PlayStation 4 PS4 Pro 1TB 4K Console - Black', 'US $349.99', '4.8'] 

scraper.build(url, wanted_list)
我々が欲しかったアイテムはページの複数のセクションにありました、そして、スクレーパーは彼ら全員を捕えようとします.それで、それは我々が心に持っているものと比較して若干の余分の情報を取り戻すかもしれません.別のページで実行しましょう.
scraper.get_result_exact('https://www.ebay.com/itm/Acer-Predator-Helios-300-15-6-144Hz-FHD-Laptop-i7-9750H-16GB-512GB-GTX-1660-Ti/114183725523')
結果:
[
    "Acer Predator Helios 300 15.6'' 144Hz FHD Laptop i7-9750H 16GB 512GB GTX 1660 Ti",
    'ACER Predator Helios 300 i7-9750H 15.6" 144Hz FHD GTX 1660Ti 16GB 512GB SSD⚡RGB',
    'US $1,229.49',
    '5.0'
]
我々が見ることができるように、我々はここに1つの余分なアイテムを持っています.私たちはget_result_exact or get_result_similar メソッドgrouped=True パラメータこれは、スクレーピング規則ごとにすべての結果をグループ化します.
scraper.get_result_exact('https://www.ebay.com/itm/Acer-Predator-Helios-300-15-6-144Hz-FHD-Laptop-i7-9750H-16GB-512GB-GTX-1660-Ti/114183725523', grouped=True)
出力:
{
    'rule_sks3': ["Acer Predator Helios 300 15.6'' 144Hz FHD Laptop i7-9750H 16GB 512GB GTX 1660 Ti"],
    'rule_d4n5': ['ACER Predator Helios 300 i7-9750H 15.6" 144Hz FHD GTX 1660Ti 16GB 512GB SSD⚡RGB'],
    'rule_fmrm': ['ACER Predator Helios 300 i7-9750H 15.6" 144Hz FHD GTX 1660Ti 16GB 512GB SSD⚡RGB'],
    'rule_2ydq': ['US $1,229.49'],
    'rule_buhw': ['5.0'],
    'rule_vpfp': ['5.0']
}
今すぐ使えるkeep_rules or remove_rules 不要なルールを解決する方法
scraper.keep_rules(['rule_sks3', 'rule_2ydq', 'rule_buhw'])

scraper.get_result_exact('https://www.ebay.com/itm/Acer-Predator-Helios-300-15-6-144Hz-FHD-Laptop-i7-9750H-16GB-512GB-GTX-1660-Ti/114183725523')
そして、結果は我々が欲しいものだけを含みます:
[
    "Acer Predator Helios 300 15.6'' 144Hz FHD Laptop i7-9750H 16GB 512GB GTX 1660 Ti",
    'US $1,229.49',
    '5.0'
]
これは間違いなく試してみる必要があるモジュールの1つです.私は数日間それを使用していると私は非常に満足している.
これがlink だから、それをチェックアウトすることができます.
どうもありがとう.