Skip to content

Instantly share code, notes, and snippets.

@Radicals27
Created November 28, 2019 06:51
Show Gist options
  • Save Radicals27/5e10a9717adee696bfdf3d6c01ebcd28 to your computer and use it in GitHub Desktop.
Save Radicals27/5e10a9717adee696bfdf3d6c01ebcd28 to your computer and use it in GitHub Desktop.
This is an eBay price scraper for Nvidia RTX2080 cards. It collects the prices and links to the items in a .csv file.
import csv
import urllib.request
from bs4 import BeautifulSoup
import time
item_links = []
price_links = []
website = "https://www.ebay.com.au/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=rtx+2080&_sacat=0&LH_TitleDesc=0&_osacat=0&_odkw=gtx+2080"
print(website)
try:
page = urllib.request.urlopen(website)
except (http.client.IncompleteRead) as e:
page = e.partial
soup = BeautifulSoup(page, 'lxml')
all_a_tags = soup.find_all("a")
all_span_tags = soup.find_all("span")
for link in all_a_tags:
try:
tester = link.get("href")
if "https://www.ebay.com.au/itm/" in link.get("href"):
if link.get("href") in item_links:
print("duplicate found")
else:
item_links.append(link.get("href"))
print(link.get("href"))
raw_filename = link.get("href")
except:
tester = None
time.sleep(3)
for link in all_span_tags:
try:
tester = link.get("class")
if "item__price" in str(link):
split_link = str(link).split('>')
split_link = split_link[1].split('<')
price_links.append(split_link[0])
print(split_link[0])
raw_price = link
except:
tester = None
print("Items collected: ", len(item_links))
print("Prices collected: ", len(price_links))
with open('All_items.csv', 'a', newline='\n') as csvFile: #append each fileshare link to a new row
writer = csv.writer(csvFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, dialect='excel')
for i in item_links:
writer.writerow([i, price_links[item_links.index(i)]])
csvFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment