Blog | Ecommerce Data | How to Scrape Product Data Using Python
Ecommerce Data

How to Scrape Product Data Using Python

How to Scrape Product Data Using Python

Even though Amazon is the leader in e-commerce marketplaces – eBay still has its fair share in the online retail industry. Brands selling online should be monitoring prices on eBay as well to gain a competitive advantage.

To scrape product data from eBay at a huge scale regularly is a challenging problem for data scientists. Here is an example of scraping eBay using python to identify the prices of mobile phones, using the same open-source tooling covered in our Best Web Scraping Tools in 2026 guide.

Lets us imagine a use case where you need to monitor the pricing of a product, say a mobile phone from eBay. Also, you want to visualize the range of price offering available on the mobile phone which you want to monitor. Moreover, you have other mobile phones under consideration so you may also want to compare their prices as well, the same kind of side by side pricing view we built in our Nike vs Adidas competitive analysis.

In this blog, we will be scraping eBay to collect the prices of phones and find out the difference between their offerings on the eBay website, similar to how we broke down pricing patterns in our H&M pricing strategy analysis.

Scraping eBay product data step by step

In this section, we will walk you through the step by step process of scraping eBay for products and their prices, the same fundamentals we cover in our guide on bypassing anti-bot systems while web scraping.

1. Selecting the required information

The very first task in web scraping is to identify the target web page. It is the web page from which you need to extract all the required information.

We will be scraping eBay for the product listings so we can just open the eBay website and type our product in their search bar and hit enter. Once page loads with all the product listing of that product, all you need to do is pull that URL out from the browser. This URL will be our target URL. In our case, the URL will be,

“https://www.ebay.com/sch/i.html?_from=R40&_nkw=galaxy+note+8&_sacat=0&_pgn=1”

Notice the two parameters in this URL i.e. “nkw” (new keyword) and “pgn” (page number) parameter. These parameters in the URL defines the search query. If we change “pgn” parameter to 2, then it will open the second page of the product listings for galaxy note 8 phone and if we were to change “nkw” to iPhone X then eBay will search for iPhone X and will show you the corresponding results. If you'd rather not manage this kind of setup yourself, our roundup of the best web scraping services in 2026 covers managed alternatives too.

2. Finalizing the tags for extraction

Once we have finalized the target web page, we need to understand its HTML layout to scrape the results out. This is the most important and critical part of web scraping and basic HTML knowledge is a pre-requisite for this step.

When on the target web page, do “inspect element” and open the developer tools window or just do CTRL+SHIFT+I. In the new window, you will find the source code of the target web page. In our case, all the products are mentioned as list elements so we have to grab all these lists.

In order to grab an HTML element, we need to have an identifier associated with it. It can be an id of that element or any class name or any other HTML attribute of the particular element. We are using the class name as the identifier. All the lists have the same class name i.e. s-card.

On further inspection, we got the class names for the product name and product price which are “s-card__title” and “s-card__price” respectively. With this information, we have successfully completed step 2!

3. Putting the scraped data in a structured format

After having our extractors/identifiers we only need to extract specific portions out from the HTML content. Once this is done, we need to organize this data into a suitable structured format. We will be creating a table where we will have all the product names in one column and their prices in the other.

4. Visualizing the results (optional)

Since we are to compare the price offerings on two different mobile phones, we will visualize the results too. This is not a mandatory step for web scraping but is more of a process to turn your collected data into some actionable insights. We will be plotting boxplots to understand the distribution of the price offerings on both galaxy note 8 and iPhone 8 mobile phones.

Required libraries and Installation

To implement web scraping for this use case, you will need python, pip (package installer for python), and BeautifulSoup library in python for web scraping. eBay now blocks plain requests-based scraping outright, so you will also need patchright, a patched fork of Playwright, to render pages like a real browser. You will also need the pandas library to organize the collected data into a structured format.

1. Installing Python and PIP – Depending upon your operating system, you can follow this blog link to setup python and Pip in your system.
2. Installing Beautiful soup library
apt-get install python-bs4
pip install beautifulsoup4
3. Installing patchright
pip install patchright
patchright install chromium
4. Installing pandas
pip install pandas

We are done setting up our environment and now can begin with the scraping implementation using python. The implementation consists of the steps discussed in the earlier section.

Python implementation for scraping eBay

In this section, we will perform two scraping operations i.e. one for the iPhone 8 and another for the galaxy note 8 mobile phones. eBay's current bot detection needs more code than a simple loop, since it can tell when a page is being driven via the Chrome DevTools Protocol, so we will define the scraping logic once as a set of functions and then call it separately for each phone.

Here are the functions we will reuse for both phones:

import logging
import random
import re
import time
from urllib.parse import urlencode

import pandas as pd
from bs4 import BeautifulSoup
from patchright.sync_api import sync_playwright

logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
logger = logging.getLogger(__name__)

CELL_PHONES_CATEGORY = "9355"
MAX_PAGES = 30
MAX_RETRIES = 4
USER_AGENT = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36")


def build_url(query, page):
params = {"_nkw": query, "_sacat": CELL_PHONES_CATEGORY, "_pgn": page}
return "https://www.ebay.com/sch/i.html?" + urlencode(params)


def parse_price(text):
match = re.search(r"[\d,]+\.?\d*", text or "")
return float(match.group().replace(",", "")) if match else None


def is_blocked(html):
return "Something went wrong on our end" in html


def extract_listings(html, model_pattern):
soup = BeautifulSoup(html, "html.parser")
listings = []

for card in soup.find_all("li", attrs={"class": lambda c: c and "s-card" in c.split()}):
title_box = card.find(attrs={"class": lambda c: c and "s-card__title" in c.split()})
if not title_box:
continue
visible_span = title_box.find(attrs={"class": lambda c: c and "clipped" not in c.split()})
title = (visible_span or title_box).get_text(strip=True)

if not title or title.lower() == "shop on ebay":
continue
if not re.search(model_pattern, title, re.IGNORECASE):
continue

price_tag = card.find(attrs={"class": lambda c: c and "s-card__price" in c.split()})
price = parse_price(price_tag.get_text(strip=True)) if price_tag else None
if price is None:
continue

link_tag = card.find("a", attrs={"class": lambda c: c and "s-card__link" in c.split()})
cond_tag = card.find(attrs={"class": lambda c: c and "s-card__subtitle" in c.split()})

shipping, location, listing_type, seller_rating = None, None, None, None
for row in card.find_all(attrs={"class": lambda c: c and "s-card__attribute-row" in c.split()}):
text = row.get_text(strip=True)
lower = text.lower()
if "delivery" in lower or "shipping" in lower:
shipping = text
elif lower.startswith("located in"):
location = text.replace("Located in", "").strip()
elif text == "Buy It Now" or "bid" in lower:
listing_type = "Auction" if "bid" in lower else "Buy It Now"
elif re.search(r"\d+(\.\d+)?%\s*positive", lower):
seller_rating = text

listings.append({
"Name": title,
"Price": price,
"URL": link_tag["href"] if link_tag else None,
"Condition": cond_tag.get_text(strip=True) if cond_tag else None,
"Shipping": shipping,
"Location": location,
"ListingType": listing_type,
"SellerRating": seller_rating,
})

return listings


def fetch_page(page, url):
for attempt in range(1, MAX_RETRIES + 1):
try:
page.goto(url, timeout=30000, wait_until="domcontentloaded")
html = page.content()
if is_blocked(html):
logger.warning("Blocked on attempt %d of %d for %s", attempt, MAX_RETRIES, url)
time.sleep(attempt * 8)
continue
return html
except Exception as e:
logger.warning("Request failed on attempt %d of %d: %s", attempt, MAX_RETRIES, e)
time.sleep(attempt * 5)
logger.error("Giving up on %s after %d attempts", url, MAX_RETRIES)
return None


def scrape_ebay(query, model_pattern):
all_listings = []
seen_urls = set()
empty_streak = 0

with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context(user_agent=USER_AGENT, locale="en-US",
viewport={"width": 1366, "height": 768})
page = context.new_page()

for page_num in range(1, MAX_PAGES + 1):
logger.info("Query '%s', page %d", query, page_num)
html = fetch_page(page, build_url(query, page_num))

if html is None:
break

page_listings = extract_listings(html, model_pattern)
new_listings = [listing for listing in page_listings if listing["URL"] not in seen_urls]
logger.info("Page %d: %d matching listings, %d new", page_num, len(page_listings), len(new_listings))

if not new_listings:
empty_streak += 1
if empty_streak >= 2:
logger.info("No new matches for two pages straight, ending here")
break
else:
empty_streak = 0
for listing in new_listings:
seen_urls.add(listing["URL"])
all_listings.extend(new_listings)

time.sleep(random.uniform(3, 6))

browser.close()

return pd.DataFrame(all_listings)
Scrapping eBay for Galaxy Note 8 products
With the functions above defined, scraping Galaxy Note 8 listings is a single call:
data_note_8 = scrape_ebay("Galaxy note 8", r"\bnote\s*8\b(?!\s*plus)")
data_note_8.to_csv("note8_prices.csv", index=False)

Collected Data for Galaxy note 8

Here is a preview of the collected data:

Scrapping eBay for iPhone 8

The iPhone 8 search works the same way, with its own model pattern:

data_iphone_8 = scrape_ebay("iPhone 8", r"\biphone\s*8\b(?!\s*plus)")
data_iphone_8.to_csv("iPhone8_prices.csv", index=False)

Collected data for iPhone 8

Here is a preview of the collected data:

Visualizing the price of the products

Now is the time to visualize the scraped results. We will be using a scatter plot to spot which listings are priced unusually high compared to the rest.

Each dot represents one listing. Listings priced far above the typical range, mostly bundle or multi-unit lots, are highlighted in red.

For iPhone 8, most of the prices lie between ₹7,215 and ₹19,800, whereas most of the galaxy note 8 phones are available in the price range of ₹12,841–₹17,667. However, variation in prices of the iPhone 8 is much more than galaxy note 8, with a handful of bundle listings pushing prices as high as ₹5,28,000. iPhone 8 is available for as little as ₹2,640 on eBay whereas the minimum cost of galaxy note 8 on eBay is around ₹3,421.

Datahut as a reliable scraping partner

There are a lot of tools that can help you scrape data yourself. However, if you need professional assistance with minimal technical know-how, Datahut can help you. We have a well-structured and transparent process for extracting data from the web in real-time and provide in the desired format. We have helped enterprises across various industrial verticals. From assistance to the recruitment industry to retail solutions, Datahut has designed sophisticated solutions for most of these use-cases.

You should join the bandwagon of using data-scraping in your operations before it is too late. It will help you boost the performance of your organization. Furthermore, it will help you derive insights that you might not know currently. This will enable informed decision-making in your business processes.

Datahut builds exactly this kind of structured, automatically refreshed marketplace data for teams doing competitive and category benchmarking in electronics, mobile devices, and other consumer marketplaces. If you want a similar side-by-side built for your own category, request a free data audit or talk to a Datahut strategist about ongoing category monitoring.

Conclusion

In this blog, we successfully used python for scraping eBay for two different products and their pricing. We also compared the available prices for galaxy note 8 and iPhone 8 to make a better purchase decision. Web scraping coupled with data science can be leveraged for smart decision making be it in the fortune 500 companies or in your day to day life.

Wish to avail web scraping services for your data needs? Contact Datahut to know more.

FAQ Section

1. Is it legal to scrape data from eBay?

Scraping publicly available data from eBay may be legal, but it could violate eBay's terms of service. Always check their policies and consult legal advice before proceeding.

2. What kind of data can you extract from eBay?

You can extract product titles, prices, seller ratings, item descriptions, shipping details, availability, and customer reviews, depending on the product page structure and visibility.

3. What tools can be used for scraping eBay?

Popular tools include Python libraries like BeautifulSoup, Scrapy, Selenium, and Playwright, especially when handling dynamic content or JavaScript-rendered pages.

4. Does eBay have anti-scraping protections?

Yes, eBay uses several anti-scraping techniques like rate limiting, IP blocking, and bot detection. Using rotating proxies, delays, and proper headers can help avoid detection.

5. What are the use cases of scraping eBay data?

Common use cases include competitor price tracking, market trend analysis, product research, inventory monitoring, and building price comparison tools.

Web data without the engineering bill

Scrapers break, IPs get blocked, and maintaining it all quietly consumes your team. Datahut has run managed extraction for 15 years: clean, structured data delivered on schedule, with none of the infrastructure on your side.

Talk to a data expert →