Issue
This is my code:
import requests
from bs4 import BeautifulSoup
url = 'https://www.newegg.com/CPUs-Processors/Category/ID-34'
r = requests.get(url)
htmlContent = r.content
soup = BeautifulSoup(htmlContent, 'html.parser')
processor_price = []
prices = soup.find_all('li', {"class": "price-current"})
for price in prices:
processor_price.append(price.text.split())
print(processor_price)
I am getting this output:
[['$414.99', '(24', 'Offers)–'], ['$709.99', '(12', 'Offers)–'], ['$319.99', '(34', 'Offers)–'], ['$439.99', '(12', 'Offers)–'], ['$199.99', '(31', 'Offers)–'], ['$71.87', '(26', 'Offers)–'],
['$289.99', '(15', 'Offers)–'], ['$164.99', '(28', 'Offers)–'], ['$214.99', '(16', 'Offers)–'], ['$304.99', '(20', 'Offers)–'], ['$199.99', '(13', 'Offers)–']]
I need this output:
['$414.99','$709.99','$319.99','$439.99'...]
Solution
Output that you got is a list in which the value you want is in the first index and so.
processor_price.append(price.text.split()[0])
Answered By - Rakesh RG
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.