-
Notifications
You must be signed in to change notification settings - Fork 4
/
current_sales.py
executable file
·105 lines (90 loc) · 3.56 KB
/
current_sales.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/local/bin/python3.11
""" A """
import time
import json
import os
import sys
from dotenv import load_dotenv
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium_recaptcha_solver import RecaptchaSolver
class SQEX:
''' A '''
def __init__(self):
self.sqexid = os.environ['SQEXID']
self.password = os.environ['PASSWORD']
self.character_id = os.environ['CHARACTER_ID']
self.retainer_count = os.environ['RETAINER_COUNT']
self.retainer_id = ( os.environ['RETAINER_ID_1'],
os.environ['RETAINER_ID_2'] )
self.options = Options()
self.driver = webdriver.Firefox(options=self.options)
self.url = 'https://na.finalfantasyxiv.com/lodestone/account/login/'
def start(self):
'''A'''
self.driver.get(self.url)
element = self.driver.find_element(By.ID, 'sqexid')
element.send_keys(self.sqexid)
element = self.driver.find_element(By.ID, 'password')
element.send_keys(self.password)
time.sleep(1)
#print("Solve reCaptcha")
#solver = RecaptchaSolver(driver=self.driver)
#recaptcha_iframe = self.driver.find_element(By.XPATH, '//iframe[@title="reCAPTCHA"]')
#solver.click_recaptcha_v2(iframe=recaptcha_iframe)
#time.sleep(5)
#print("Going on...")
input("Bypass reCaptura...")
#while True:
# try :
# box = self.driver.find_element(By.CLASS_NAME, 'recaptcha-checkbox')
# print(box)
# value = box.get_attribute('aria-checked').lower()
# print(value)
# if box.get_attribute('aria-checked').lower() == 'true':
# break
# except Exception as e:
# print(e)
self.driver.find_element(By.ID, 'view-loginArea').click()
wait = WebDriverWait(self.driver, 10)
element = wait.until(
EC.element_to_be_clickable((By.CLASS_NAME,
'osano-cm-accept-all')))
element.click()
self.driver.find_element(By.CLASS_NAME, 'bt_character_login').click()
time.sleep(1)
items=[]
for entry in self.retainer_id:
url = 'https://na.finalfantasyxiv.com/lodestone/character/' + \
self.character_id + '/retainer/' + entry + '/'
self.driver.get(url)
element = wait.until(
EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT,
'Sale Inventory')))
element.click()
lst = self.driver.find_element(By.NAME, 'tab__market-list')
elements = lst.find_elements(By.CLASS_NAME, 'item-list__name')
for elm in elements:
full_text = elm.text
blob = elm.find_element(By.TAG_NAME, 'span').text
item_text = full_text.replace(blob, '')
items.append(item_text)
return list(set(items))
def close(self):
''' A '''
self.driver.close()
if __name__ == "__main__":
load_dotenv()
webscraper = SQEX()
dct = {
"items" : webscraper.start()
}
webscraper.close()
with open('current.json', 'w', encoding='utf8') as f:
json.dump(dct, f)
print(dct)
print(len(dct['items']))