0

I am trying to scrape the price of an item off of an eCommerce website using beautiful soup with python 3. What else do I have to do to extract the price from my first pull?

I have tried other combinations of the code, but do not have a strong understanding of this method.

import requests
from bs4 import BeautifulSoup

page = requests.get('https://www.walmart.com/ip/GoGreen-Power-6-Outlet-Surge-Protector-16103MS-2-5-cord-White/46097919')
soup = BeautifulSoup(page.text, 'html.parser')

price_hide = soup.find(class_='price-characteristic')
print(price_hide)

wprice = price_hide.find_all(content)
print(wprice)

First print function works

<span class="price-characteristic" content="3.98" itemprop="price">3</span>

Second one not so much.

I would expect the content price of 3.98 to be printed

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
96jeremy
  • 17
  • 2
  • 9
  • 1
    `price_hide['content']` or `price_hide.get('content')` – Smart Manoj Jun 05 '19 at 02:19
  • 1
    Possible duplicate of [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – QHarr Jun 05 '19 at 05:58

1 Answers1

0

It's easier than you think, try out the following code:

from bs4 import BeautifulSoup
import requests

page = requests.get('https://www.walmart.com/ip/GoGreen-Power-6-Outlet-Surge-Protector-16103MS-2-5-cord-White/46097919')
soup = BeautifulSoup(page.text, 'html.parser')

price_hide = soup.find(class_='price-characteristic')
print(price_hide)

wprice = price_hide["content"]
print(wprice)

I hope this helps!

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
  • This answer was great and the technique works on everything I have tried up to this html code below `
    $6.92  / ea
    ` How do I get the 6.92?
    – 96jeremy Jun 12 '19 at 01:17