Web Scraping ebay with selenium and export data to csv

Dependencies

Run jupyter

Imports

from selenium import webdriver
import os
import time
from selenium.webdriver.common.keys import Keys
import pandas as pd
ruta = os.getcwd()
driver_path = ‘{}\chromedriver.exe’.format(ruta)
driver = webdriver.Chrome(driver_path)
driver.get(‘https://www.ebay.com/')
ar = "TV"
articulo = driver.find_element_by_xpath('//input[@placeholder="Buscar artículos"]')
articulo.send_keys(ar)
enviar = driver.find_element_by_xpath('//input[@value="Buscar"]')
enviar.click()
time.sleep(2)
precios = driver.find_elements_by_xpath('//ul[@class="srp-results srp-list clearfix"]/li//div[@class="s-item__info clearfix"]//div[@class="s-item__details clearfix"]/div[1]/span')
precios = [i.text for i in precios]
urls = driver.find_elements_by_xpath('//ul[@class="srp-results srp-list clearfix"]/li//div[@class="s-item__info clearfix"]//a[@class="s-item__link"]')
urls = [i.get_attribute('href') for i in urls]
for i in range(4):# Obtener todos los nombresnombres = driver.find_elements_by_xpath('//ul[@class="srp-results srp-list clearfix"]/li//h3[@class="s-item__title"]')nombres = [i.text for i in nombres]#Obtener todos los preciosprecios = driver.find_elements_by_xpath('//ul[@class="srp-results srp-list clearfix"]/li//div[@class="s-item__info clearfix"]//div[@class="s-item__details clearfix"]/div[1]/span')precios = [i.text for i in precios]#Obtener todas las urlsurls = driver.find_elements_by_xpath('//ul[@class="srp-results srp-list clearfix"]/li//div[@class="s-item__info clearfix"]//a[@class="s-item__link"]')urls = [i.get_attribute('href') for i in urls]lista_nombres.extend(nombres)lista_precios.extend(precios)lista_urls.extend(urls)try:siguiente = driver.find_element_by_xpath('//a[@class="pagination__next icon-link"]')siguiente.click()except:break
df = pd.DataFrame({"nombre":lista_nombres,"precio":lista_precios,"url": lista_urls })
df.to_csv('ebay_scraper.csv')

--

--

--

My Youtube channel https://www.youtube.com/channel/UCj5WYkcZwQSoQlOHuL_AaGQ There you will find how to contact me too.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Are Communication Service Providers and Hyperscalers going to rule our Next Generation.

Guide for installing ECDSA Keep node

All About Flask 2.0

Evangelicalism in America is nearing extinction due to the movement’s devotion to politics at the…

How to use Multithreading and Multiprocessing — A Beginner’s guide to parallel and concurrent…

App Development Cost Part 3

How GammaSwap Uses Storj

A glance at KUOSC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andres Felipe Rojas

Andres Felipe Rojas

My Youtube channel https://www.youtube.com/channel/UCj5WYkcZwQSoQlOHuL_AaGQ There you will find how to contact me too.

More from Medium

Web Scraping Tables from Wikipedia using BeautifulSoup in Python

Extract Table Data From Wikipedia Using Web Scraping With Python

Easy way to Scrape a Table from a website with Python

How to interact (read / write) data from/to your Google Sheets using Python and Google Sheets API