Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.common.exceptions import NoSuchElementException
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.chrome.options import Options as ChromeOptions
- import math
- import time
- cd = "D:\\Code\\Python\\chromedriver.exe"
- loot = "D:\\Code\\Python\\loot.txt"
- chrome_bin = "D:\\Programs\\Google\\Chrome\\Application\\chrome.exe"
- #1 = "https://www.wowhead.com/battle-for-azeroth-dungeons-overview"
- aa = "https://www.wowhead.com/siege-of-boralus"
- bb = "https://www.wowhead.com/freehold"
- cc = "https://www.wowhead.com/shrine-of-the-storm"
- dd = "https://www.wowhead.com/tol-dagor"
- ee = "https://www.wowhead.com/waycrest-manor"
- ff = "https://www.wowhead.com/ataldazar"
- gg = "https://www.wowhead.com/the-motherlode"
- hh = "https://www.wowhead.com/temple-of-sethraliss"
- ii = "https://www.wowhead.com/the-underrot"
- jj = "https://www.wowhead.com/kings-rest"
- boe = "https://www.wowhead.com/armor/side:3/quality:4?filter=3:166;1:8;0:0"
- uldir = "https://www.wowhead.com/uldir"
- ToS = "http://www.wowhead.com/tomb-of-sargeras"
- legendary = "http://www.wowhead.com/items/quality:5/slot:16:18:5:8:11:10:1:23:7:21:2:22:13:24:15:28:14:4:3:19:25:12:17:6:9?filter=166:2;7:1;0:0"
- argus = "http://www.wowhead.com/antorus-the-burning-throne"
- seat = "http://www.wowhead.com/the-seat-of-the-triumvirate"
- cos = "http://www.wowhead.com/court-of-stars"
- coen = "http://www.wowhead.com/cathedral-of-eternal-night"
- hov = "http://www.wowhead.com/halls-of-valor"
- neth = "http://www.wowhead.com/neltharions-lair"
- eye = "http://www.wowhead.com/eye-of-azshara-dungeon"
- dht = "http://www.wowhead.com/darkheart-thicket"
- vh = "http://www.wowhead.com/violet-hold"
- brh = "http://www.wowhead.com/black-rook-hold"
- maw = "http://www.wowhead.com/maw-of-souls"
- votw = "http://www.wowhead.com/vault-of-the-wardens"
- arc = "http://www.wowhead.com/the-arcway"
- kara = "http://www.wowhead.com/return-to-karazhan"
- leggo = "http://www.wowhead.com/armor/side:3/quality:5?filter=166;7;0#0-1-2"
- #HTML ERROR Varnish cache server
- #/html/body/p[3]
- link = [uldir, boe, bb, aa, cc, dd, ee, ff, gg, hh, ii, jj]
- def main():
- k = 0
- for i in link:
- print(i)
- sim(i)
- ++k
- time.sleep(500)
- print("Sims Complete")
- def sim(link):
- opts = ChromeOptions()
- opts.binary_location = chrome_bin
- driver = webdriver.Chrome(executable_path=cd)
- while True:
- try:
- driver.set_window_size(1000, 5000)
- driver.set_page_load_timeout(20)
- break
- except:
- time.sleep(1)
- while True:
- try:
- driver.get(link)
- break
- except:
- time.sleep(5)
- time.sleep(10)
- #get what kind of wowhead table it
- try:
- driver.find_element_by_xpath("//*[@id='tab-drops']/div[1]/div[1]/span/b[2]").get_attribute("innerHTML")
- dort = 2
- except:
- dort = 1
- #filter
- try:
- time.sleep(1)
- if dort == 2:
- driver.find_element_by_xpath("//*[@id='tab-drops']/div[1]/span/input").send_keys("3")
- elif dort == 1:
- driver.find_element_by_xpath("//*[@id='lv-items']/div[1]/span/input").send_keys("3")
- print("filter")
- time.sleep(1)
- except:
- print("cant filter")
- time.sleep(0)
- if dort == 2:
- try:
- count = driver.find_element_by_xpath("//*[@id='tab-drops']/div[1]/div[1]/span/b[3]").get_attribute("innerHTML")
- except:
- print("cant find countdort == 2")
- if dort == 1:
- try:
- count = driver.find_element_by_xpath("//*[@id='lv-items']/div[1]/div[1]/span/b[3]").get_attribute("innerHTML")
- except:
- print("cannot find count dort == 1")
- print("Count is: " + count)
- try:
- count = math.ceil(float(count)/50)
- except:
- print("MATH IS HARD")
- time.sleep(999)
- print(count)
- if dort == 2:
- perpage = int(driver.find_element_by_xpath("//*[@id='tab-drops']/div[1]/div[1]/span/b[3]").get_attribute("innerHTML"),10)
- elif dort == 1:
- perpage = int(driver.find_element_by_xpath("//*[@id='lv-items']/div[1]/div[1]/span/b[3]").get_attribute("innerHTML"),10)
- print(perpage)
- lastpage = perpage
- while lastpage > 50:
- lastpage = lastpage - 50
- print(lastpage)
- if perpage > 50:
- #do all the full 50 page lists
- for j in range (1, int(count)):
- print("Page " + str(count) + " of " + str(j))
- for i in range (1, 51):
- print("columns " + str(perpage) + " of " + str(i))
- parcePage(i, driver, dort, link)
- try:
- print("Next Page")
- print(j)
- print(int(count))
- while j != int(count):
- if dort == 2:
- print("click tab-drops")
- driver.find_element_by_xpath("//*[@id='tab-drops']/div[1]/div[1]/a[3]").click()
- print("clicked ")
- break
- elif dort == 1:
- print("click lv-items")
- driver.find_element_by_xpath("//*[@id='lv-items']/div[1]/div[1]/a[3]").click()
- print("clicked ")
- break
- except:
- print("Failed to click NEXT retrying")
- time.sleep(1)
- time.sleep(5)
- for i in range (1, lastpage+1):
- print("columns " + str(perpage) + " of " + str(i))
- parcePage(i, driver, dort, link)
- print("quitting")
- print("Page " + str(count))
- time.sleep(5)
- driver.quit()
- def dungLoc(driver):
- while True:
- try:
- driver.switch_to_window(driver.window_handles[1])
- driver.find_element_by_xpath("//*[@id='tab-dropped-by']/div[2]/table/thead/tr/th[2]").click()
- srcItem = driver.find_element_by_xpath("//*[@id='tab-dropped-by']/div[2]/table/tbody/tr[1]/td[4]/a").get_attribute("innerHTML")
- break
- except:
- time.sleep(1)
- driver.close()
- driver.switch_to_window(driver.window_handles[0])
- return srcItem
- def tosBoss(driver):
- time.sleep(3)
- driver.switch_to_window(driver.window_handles[1])
- try:
- srcItem = driver.find_element_by_xpath("//*[@id='tab-dropped-by']/div[2]/table/tbody/tr/td[2]/a").get_attribute("innerHTML")
- except:
- driver.close()
- driver.switch_to_window(driver.window_handles[0])
- return "any"
- driver.close()
- driver.switch_to_window(driver.window_handles[0])
- return srcItem
- def trinketType(driver):
- while True:
- print("TRINKET TYPE")
- time.sleep(2)
- try:
- driver.switch_to_window(driver.window_handles[1])
- class1 = driver.find_element_by_xpath("//*[@id='lootspecs']/li[1]").get_attribute("innerHTML")
- class2 = driver.find_element_by_xpath("//*[@id='lootspecs']/li[3]").get_attribute("innerHTML")
- try:
- class3 = driver.find_element_by_xpath("//*[@id='lootspecs']/li[5]").get_attribute("innerHTML")
- except:
- class3 = driver.find_element_by_xpath("//*[@id='lootspecs']/li[2]").get_attribute("innerHTML")
- break
- except:
- try:
- print("all specs")
- q = 'all'
- driver.close()
- driver.switch_to_window(driver.window_handles[0])
- return q
- except:
- time.sleep(1)
- class1 = class1.split(":")
- class1 = class1[0] #First
- class2 = class2.split(":")
- class2 = class2[0] #Third
- class3 = class3.split(":")
- class3 = class3[0] #Fifth
- #Spellcaster mage druid hunter priest
- #Healer Pally Druid Priest sham mook
- #Tank Pally Warrior Druid DK Moonk
- #Mele Pally Warrior Druid DK Hunter
- c = 'error'
- if class1 == 'Paladin':
- if class3 == 'Monk':
- c = 'tank'
- if class2 == 'Priest':
- c = 'healer'
- if class3 == 'Warrior':
- c = 'strength'
- if class3 == 'Hunter':
- c = 'melee'
- if class1 == 'Druid':
- c = 'agility'
- if class1 == 'Mage':
- c = 'ranged'
- #close
- driver.close();
- driver.switch_to_window(driver.window_handles[0])
- return c
- def parcePage(i, driver, dort, link):
- #Find data
- if dort == 2:
- print("Trying Drops tab-drops")
- modeCheck = driver.find_element_by_xpath("//*[@id='tab-drops']/div[2]/table/thead/tr/th[3]/div/a/span/span").get_attribute("innerHTML")
- if modeCheck == "Mode":
- print("MODE RULES")
- name = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[3]/div/a"]
- nString = "".join(name)
- #tier //*[@id="tab-drops"]/div[2]/table/tbody/tr[1]/td[11]/a
- type = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]]/td[11]/a"]
- tierString = "".join(type)
- type = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[11]/a"] #Type
- tString = "".join(type)
- slot = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[9]"] #Slot
- sString = "".join(slot)
- gSource = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[10]/div/a"] #location
- gString = "".join(gSource)
- source = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]td[10]/div/a"] #sub location of existant
- eString = "".join(source)
- else:
- print("NORMAL RULES")
- name = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[3]/div/a"]
- nString = "".join(name)
- #tier //*[@id="tab-drops"]/div[2]/table/tbody/tr[1]/td[11]/a
- type = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]]/td[11]/a"]
- tierString = "".join(type)
- type = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[10]/a"] #Type
- tString = "".join(type)
- slot = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[8]"] #Slot
- sString = "".join(slot)
- gSource = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[9]"] #location
- gString = "".join(gSource)
- source = ["//*[@id='tab-drops']/div[2]/table/tbody/tr[", str(i), "]/td[9]/div/a"] #sub location of existant
- eString = "".join(source)
- elif dort == 1:
- print("Trying Items lv-items")
- modeCheck = driver.find_element_by_xpath("//*[@id='lv-items']/div[2]/table/thead/tr/th[3]/div/a/span/span").get_attribute("innerHTML")
- if modeCheck == "Mode":
- print("MODE RULES")
- name = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[3]/div/a"]
- nString = "".join(name)
- #tier //*[@id="lv-items"]/div[2]/table/tbody/tr[1]/td[11]/a
- type = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]]/td[11]/a"]
- tierString = "".join(type)
- type = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[11]/a"] #Type
- tString = "".join(type)
- slot = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[9]"] #Slot
- sString = "".join(slot)
- gSource = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[10]/div/a"] #location
- gString = "".join(gSource)
- source = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]td[10]/div/a"] #sub location of existant
- eString = "".join(source)
- else:
- print("NORMAL RULES")
- name = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[3]/div/a"]
- nString = "".join(name)
- #tier //*[@id="lv-items"]/div[2]/table/tbody/tr[1]/td[11]/a
- #//*[@id='lv-items']/div[2]/table/tbody/tr[1]/td[11]
- type = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[11]/a"]
- tierString = "".join(type)
- type = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[10]/a"] #Type
- tString = "".join(type)
- slot = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[9]"] #Slot
- sString = "".join(slot)
- gSource = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[9]"] #location
- gString = "".join(gSource)
- source = ["//*[@id='lv-items']/div[2]/table/tbody/tr[", str(i), "]/td[9]/div/a"] #sub location of existant
- eString = "".join(source)
- elif dort == 0:
- exit(-1)
- #grab data
- #id
- while True:
- try:
- idItem = driver.find_element_by_xpath(nString).get_attribute("href")
- print(idItem)
- id = idItem.split("=")
- id = id[1].split("&")
- idItem = id[0]
- print(idItem)
- break
- except:
- print("Failed to grab the ID retrying")
- print(nString)
- time.sleep(1)
- #name
- while True:
- try:
- nItem = driver.find_element_by_xpath(nString).get_attribute("innerHTML") #name
- nItem = nItem.replace(" ", "_")
- nItem = nItem.replace("'", "''")
- print(nItem)
- break
- except:
- print("Failed to grab the name retrying")
- time.sleep(1)
- #Slot
- while True:
- try:
- sItem = driver.find_element_by_xpath(sString).get_attribute("innerHTML")
- print(sItem)
- break
- except:
- print("Failed to grab the slot retrying")
- time.sleep(1)
- #type
- while True:
- #Tier
- try:
- try:
- print("tierString")
- print(tierString)
- tItem = driver.find_element_by_xpath(tierString).get_attribute("innerHTML")
- print("split")
- type = tItem.split()
- tItem = type[0]
- break
- except:
- print("tString")
- tItem = driver.find_element_by_xpath(tString).get_attribute("innerHTML")
- print("split")
- type = tItem.split()
- tItem = type[0]
- break
- except:
- print("Failed to something in Tier")
- time.sleep(5)
- #Trinket Type
- if sItem == 'Trinket':
- print("trinket found")
- driver.find_element_by_xpath(nString).send_keys(Keys.CONTROL + Keys.SHIFT + Keys.RETURN)
- tItem = trinketType(driver)
- print(tItem)
- #source
- print("SOURCE")
- #format what it found
- if dort == 2:
- driver.find_element_by_xpath(nString).send_keys(Keys.CONTROL + Keys.SHIFT + Keys.RETURN)
- srcItem = tosBoss(driver)
- elif dort == 1:
- srcItem = "drop"
- srcItem = srcItem.replace(" ", "_")
- srcItem = srcItem.replace("'", "''")
- print(srcItem)
- wtf(idItem, nItem.lower(), tItem.lower(), sItem.lower(), srcItem.lower(), link)
- def wtf(itemid, name, type, slot, source, link):
- link = link.split("/")
- link = link[3]
- link = link.replace("-","_")
- f = open(link + ".txt", 'a')
- # //ITEM ID, ITEM NAME, ARMOR TYPE, SLOT, BOSS, TABLE
- print("\"INSERT INTO "+ link +" VALUES(" + itemid + ", '" + name + "', '" + type + "', '" + slot + "', '" + source + "', '" + link + "');\"" + "\n")
- f.write("\"INSERT INTO "+ link +" VALUES(" + itemid + ", '" + name + "', '" + type + "', '" + slot + "', '" + source + "', '" + link + "');\"" + "\n")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement