1. Home
  2. Docs
  3. BeautifulSoup
  4. Save to Excel

Save to Excel

import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://www.newegg.com/Video-Cards-Video-Devices/Category/ID-38?Tpk=graphics%20card"
response = requests.get(url)
soup = BeautifulSoup(response.content,'html.parser')
data_list = []

item_containers = soup.find_all('div', class_='item-container')
# Loop through each item container to get the image title and a text
for container in item_containers:
    # Get Brand Name
    image = container.find('a',class_='item-brand')
    brand=image.find('img')
#     print(brand['title'])
    
    product_title = container.find('a',class_='item-img')
    title =product_title.find('img')
#     print(title['title'])
    
    data_list.append({"Image Title":title['title'],"Brand":brand['title'] })

    
df = pd.DataFrame(data_list)
df.to_excel("output.xlsx",index=False)

How can we help?