Home > Blockchain >  Selenium scrapping probleme on python nothing append
Selenium scrapping probleme on python nothing append

Time:07-17

I try to scrap this page and all the result of sells.

But nothing append, the code return me nothing. I would like to have the seller buyer price and date on dataframe or something like this

Best

https://www.fxhash.xyz/marketplace/generative/15063

driver =  webdriver.Chrome(ChromeDriverManager().install())  #webdriver.Firefox()
driver.get("https://www.fxhash.xyz/marketplace/generative/15063")

# que la page charge avant de passer à la suite
time.sleep(5)

#driver.find_element_by_id('activity').click()

driver.find_element(By.XPATH, '//div[contains(text(),"activity")]').click()
*#Find the acticity page*
activities = driver.find_elements(By.XPATH, '//article[@]')


time.sleep(5)
*#grab the element*
elements_list = driver.find_elements_by_xpath("//div[contains(@class, 'Activity_container__E7eID Activity_activity__kwRfH')]/a[contains(@class, 'Action_container__uURkZ Action_is_link__7x4O4')]")

for element in elements_list:
    driver.execute_script("arguments[0].scrollIntoView(true);", element)
    print(element.get_attribute("href"))

enter image description here

CodePudding user response:

You can scrape all data from API GraphQL.
Here you have an example:

import requests


def do_request(skip):
    json_data = {
        'operationName': 'GenTokActiveListings',
        'variables': {
            'filters': {},
            'id': 15063,
            'skip': skip,
            'take': 20,
            'sort': {
                'listingCreatedAt': 'DESC',
            },
        },
        'query': 'query GenTokActiveListings($id: Float!, $filters: ObjktFilter, $sort: ObjktsSortInput, $skip: Int, $take: Int) {  generativeToken(id: $id) {    id    activeListedObjkts(filters: $filters, sort: $sort, skip: $skip, take: $take) {      id      version      name      slug      duplicate      metadata      activeListing {        id        version        price        issuer {          id          name          flag          avatarUri          __typename        }        __typename      }      owner {        id        name        flag        avatarUri        __typename      }      __typename    }    __typename  }}',
    }
    print("Getting first "   str(next_elements   20)   " elements!!!")
    response = requests.post('https://api.fxhash.xyz/graphql', json=json_data)
    return response.json()


next_elements = 0
for i in range(0, 100):
    data = do_request(next_elements)
    array = data["data"]["generativeToken"]["activeListedObjkts"]
    if not array:
        print("Finish array is empty!")
        break
    for element in array:
        print("Name: "   element["name"])
        print("Owner name: "   str(element["owner"]["name"]))
        print("Owner id: "   str(element["owner"]["id"]))
        print("Price: "   str(element["activeListing"]["price"]))
    next_elements  = 20

OUTPUT:

Getting first 20 elements!!!
Name: A Bugged Forest #491
Owner name: DeD_X
Owner id: tz1bBgjBboqksQDxTpADTe22otokenRajpmq
Price: 1550000000
Name: A Bugged Forest #525
Owner name: None
Owner id: tz1hzHjsa9sExwjRVFPxJnuVak2qpKmKrame
Price: 1600000000
  • Related