I scraped data and saved the scraped data to the five lists and I created the table with five rows, now i do not know how to save my scraped data to the database.
my code is:
import requests
from bs4 import BeautifulSoup
import re
import mysql.connector
url = 'https://www.ebay.com/b/Cars-Trucks/6001?_fsrp=0&_sacat=6001&LH_BIN=1&LH_ItemCondition=3000%7C1000%7C2500&rt=nc&_stpos=95125&Model%2520Year=2020%7C2019%7C2018%7C2017%7C2016%7C2015'
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
car_titles =[]
title = soup.find_all('h3', class_='s-item__title', limit = 20)
for title_of_car in title:
car_titles.append(title_of_car.text)
car_brands = []
brands = soup.find_all('span', class_='s-item__dynamic s-item__dynamicAttributes1', limit = 20)
for brand in brands:
brand = re.sub(r'Make: ','', brand.text)
car_brands.append(brand)
car_models = []
models = soup.find_all('span', class_='s-item__dynamic s-item__dynamicAttributes2', limit = 20)
for model in models:
model = re.sub(r'Model: ', '', model.text)
car_models.append(model)
car_transmissions = []
transmissions = soup.find_all('span', class_='s-item__dynamic s-item__dynamicAttributes3', limit = 20)
for transmission in transmissions:
transmission = re.sub(r'Transmission: ', '', transmission.text)
car_transmissions.append(transmission)
car_prices = []
char_list = ['\$', '\,', '\.']
prices = soup.find_all('span', class_='s-item__price', limit = 20)
for price in prices:
price = re.sub('|'.join(char_list), '', price.text)
car_prices.append(int(price))