0

I have a block of code that is supposed to scrape the product title, product price, and number the product starting from 1. However, I don't understand the line print('%s) Price: %s, Product: %s'% (count, productPrice, productName)), specifically the placement of the ' . Why is it in front of the first %s and behind the third %s? And why is there a % after the ' behind the third %s? Thanks in advance!

import requests
from bs4 import BeautifulSoup
url = 'https://scrapingclub.com/exercise/list_basic/?page=1'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
items = soup.find_all('div', class_='col-lg-4 col-md-6 mb-4')
count = 1
for i in items:
    productName = soup.find('h4', class_='card-title').text
    productPrice = soup.find('h5').text
    print('%s) Price: %s, Product: %s'% (count, productPrice, productName))
    count = 1 + count
Sean Taylor
  • 159
  • 5

0 Answers0