Web crawler/spider

0

Witam.

próbuje zrobić program, który pobierze zahaszowane numery transakcji kryptowaluty z tej strony: https://etherscan.io/txs

import requests
from bs4 import BeautifulSoup


def trade_spider(max_pages):
    page = 1
    while page <= max_pages:
        url = 'https://etherscan.io/txs?p=' + str(page)
        source_code = requests.get(url)
        plain_text = source_code.text
        soup = BeautifulSoup(plain_text, 'html.parser')
        for link in soup.find_all('a', {'class':'myFnExpandBox_searchVal'}):
            href = link.get('href')
            print(href)
        page = page + 1

print(trade_spider(1))

jestem początkujący w pythonie, nie mialem tego do tej pory na studiach i bazuje na tym, co znajdę w internecie. i wg. tego co znalazlem, program powinien wyglądac tak. Jednakze, program wykonuje sie, ale nic nie zwraca. Czy ktos moglby mnie naprowadzić jak to rozwiązać? z góry dziekuje

0

Zobacz sobie co jest w print(plain_text). Okazuje się, że Cloudflare blokuje dostęp i dlatego nie ma tych linków.

Wygląda na to, że ta platforma ma API, więc powinieneś go użyć zamiast czytać ze strony: https://etherscan.io/apis

1
from requests_html import HTMLSession

class scraper(HTMLSession):
    def __init__(self):
        HTMLSession.__init__(self)
        self.link = "https://etherscan.io/txs?p="

    def _get_html(self, page):
        return self.get(self.link+str(page))

    def scrap_hash(self, page):
        main_html = self._get_html(page)
        hashes = main_html.html.find("span[class='hash-tag text-truncate']")
        return ([x.text for x in hashes])

s = scraper()
print(s.scrap_hash(1))

A jesli chcesz href to:

def scrap_hash(self, page):
       main_html = self._get_html(page)
       hashes = main_html.html.find("span[class='hash-tag text-truncate'] a")
       return ([x.attrs["href"] for x in hashes])

1 użytkowników online, w tym zalogowanych: 0, gości: 1