Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote this page scraper using python. I want to get all the prices of the tires and store them in a csv file. All

I wrote this page scraper using python. I want to get all the prices of the tires and store them in a csv file. All the prices are stored in a html structure like this. How do I grab each price and store it to the csv file along with the tire name in 2 columns?

image text in transcribed

import requests import csv from datetime import datetime from bs4 import BeautifulSoup

# for tire and review page

# download the page myurl = requests.get("https://www.goodyearautoservice.com/en-US/tires/all-season")

# create BeautifulSoup object soup = BeautifulSoup(myurl.text, 'html.parser')

# get all the tire info we need, specify where the info is located h3 = soup.find_all('h3', class_ = "baseball-card__title")

for tireblock in h3: # find the children in tire block children = tireblock.findChildren() first = [] for child in children: # grab the text in the b tags print(child.get_text())

price = soup.find_all('span', class_ = "baseball-card__price") for listprice in price: orig = price[0].text.strip() print(orig)

# create csv file name, and use 'w' since we are only writing to file with open('tireinfo.csv', 'w') as csv_file: # iterate through our arrays for f in zip(first): # concatenate both lines to match them p csv_file.write(str(f)) # for csv file formatting, start each on a new line csv_file.write(" ") print(f)

?
Starting at
span class="baseball-cardprice" ?temprop="price">$139.99 -
s/divs ?
Starting at
span class="baseball-cardprice" ?temprop="price">$139.99 -
s/divs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions