Lukemul69
Lukemul69

Reputation: 187

Print returns none even though there its not

Hey I am trying to scrape a website for pricing. It returns [] even though on the search page it has a value of $79.99. I only want it to pull the first price from the search page. I can't seem to figure out what I am doing wrong.

bburl = "https://www.ebgames.ca/SearchResult/QuickSearch?q=animal+crossing"

def bestbuy():
    proxies = get_proxy()
    result = requests.get(bburl,headers=header,timeout=12,proxies=proxies)
    soup = BeautifulSoup(result.content, 'lxml')

    titles = soup.title
    price = soup.find_all('span',attrs={'class':'megaButton buyTier3 cartAddNoRadio'})

    print(titles)
    print(price)

It returns this

<title>EB Games | The largest video game retailer in Canada. Play. Trade. Save.  - EBGames.ca </title>
[]

Upvotes: 0

Views: 71

Answers (1)

MendelG
MendelG

Reputation: 20048

The class megaButton buyTier3 cartAddNoRadio is in an a tag not a span. To only get the first element use .find() instead of find_all().

import requests
from bs4 import BeautifulSoup

bburl = "https://www.ebgames.ca/SearchResult/QuickSearch?q=animal+crossing"

def bestbuy():
    result = requests.get(bburl)
    soup = BeautifulSoup(result.content, 'lxml')

    price = soup.find('a',attrs={'class': 'megaButton buyTier3 cartAddNoRadio'})

    print(price.get_text(strip=True, separator=' '))


bestbuy()

Outputs:

New $79.99

Upvotes: 2

Related Questions