Created
June 8, 2021 20:19
-
-
Save auxermen/d3afc5900896bbaa43b316d545601800 to your computer and use it in GitHub Desktop.
GW2BLTC scrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
import keyboard | |
import time | |
import re | |
import pyperclip | |
# list of all urls that should be scraped for items, make sure to add '&ipg=200&cust-search=sell%2Cbuy%2Cprofit-pct' at the end | |
URLS = ['https://www.gw2bltc.com/en/tp/search?rarity=Legendary&sell-min=100000&profit-pct-min=10&cust-search=sell%2Cbuy%2Cprofit-pct', | |
'https://www.gw2bltc.com/en/tp/search?rarity=Rare&level-min=50&level-max=70&sell-min=300000&profit-pct-min=25&ipg=200&cust-search=sell%2Cbuy%2Cprofit-pct', | |
'https://www.gw2bltc.com/en/tp/search?rarity=Basic&level-min=30&level-max=60&profit-pct-min=5&profit-pct-max=20&ipg=200&cust-search=sell%2Cbuy%2Cprofit-pct',] | |
# store items in a dict, key = 'name - cost', value = ROI float | |
# example: items_dict = {'Berserker\'s Iron Ring - 60203': 50.9, 'Berserker\'s Iron Ring - 9850': 100.2, 'Mournstone Earring - 55499': 49.2} | |
items_roi = {} | |
# loop over all urls, get request, parse items and add them into items dictionary | |
for URL in URLS: | |
r = requests.get(URL) | |
soup = BeautifulSoup(r.content, 'html.parser') | |
table_result = soup.find('table', class_='table-result') | |
if not table_result: | |
continue | |
items_data = table_result.find_all('td') | |
# 0 - item img, 1 - item name, 2 - sell, 3 - buy, 4 - ROI | |
for i in range(0, len(items_data), 5): | |
item_name = items_data[i+1].find('a').text | |
item_sell = 0 | |
sell_gold = items_data[i+2].find('span', class_='cur-t1c') | |
if sell_gold: | |
item_sell += int(sell_gold.text.replace(',', '')) * 10000 | |
sell_silver = items_data[i+2].find('span', class_='cur-t1b') | |
if sell_silver: | |
item_sell += int(sell_silver.text) * 100 | |
sell_bronze = items_data[i+2].find('span', class_='cur-t1a') | |
if sell_bronze: | |
item_sell += int(sell_bronze.text) | |
items_roi_key = item_name + ' - ' + str(item_sell) | |
roi = float(items_data[i+4].find('span', attrs={'title': True})['title'].replace(',', '')) | |
items_roi[items_roi_key] = roi | |
# to not send requests too fast | |
time.sleep(1) | |
print('Found %i items!' % len(items_roi)) | |
# sort dictionary by values (ROI) descending | |
items_roi = dict(sorted(items_roi.items(), key=lambda item: item[1], reverse=True)) | |
for item, roi in items_roi.items(): | |
print(item + ', ' + str(roi) + '%') | |
item_name = re.search('(.*) -', item).group(1) | |
pyperclip.copy(item_name) | |
keyboard.wait('space') | |
keyboard.wait('esc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment