Home > Net >  AttributeError: 'NoneType' object has no attribute 'find' -- beautifulsoup
AttributeError: 'NoneType' object has no attribute 'find' -- beautifulsoup

Time:09-28

I am trying to scrape cryptocurrency rates from google search results but encountering the error as noted in the title.

Here is my code

from bs4 import BeautifulSoup
import requests

def cryptoPrice(crypto):
    url = "https://www.google.com/search?q="   crypto   "price"

    req = requests.get(url)

    soupObject = BeautifulSoup(req.text, 'html.parser')
    element = soupObject.find("div", {"class": "card-section PZPZlf"}).find("div").find("span", {"class": 'pclqee'}).text

    return element


price = cryptoPrice('bitcoin')
print(price)

CodePudding user response:

You can first try to print soup object and find manually the tag related to price and you can find associate value to it!

def cryptoPrice(crypto):
    url = "https://www.google.com/search?q="   crypto   "price"
    req = requests.get(url)

    soup = BeautifulSoup(req.text, 'html.parser')
    value=soup.find('div',class_="BNeawe iBp4i AP7Wnd").get_text()

    return value


price = cryptoPrice('ethereum')
price1 = cryptoPrice('bitcoin')
print(price)
print(price1)
  • Related