-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebstuff.py
52 lines (39 loc) · 1.65 KB
/
webstuff.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
import selenium
from selenium import webdriver
from selenium.webdriver import ChromeOptions
class AnimeEntry:
def __init__(self, title, imageHTML, rank):
self.title = title
self.imageHTML = imageHTML
self.rank = rank
def find_list(type):
#TODO specify web driver path
#e.g. PATH = "D:\Coding\Python_Stuff\Chrome Driver\chromedriver.exe"
PATH = _________
chrome_options = ChromeOptions()
chrome_options.add_argument('headless');
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options, executable_path=PATH)
top_airing = "//*[@id='content']/div[2]/article[1]/div/div/ul/child::*"
top_upcoming = "//*[@id='content']/div[2]/article[3]/div/div/ul/child::*"
top_alltime = "//*[@id='content']/div[2]/article[5]/div/div/ul/child::*"
top_elements = []
driver.get("https://myanimelist.net/")
driver.implicitly_wait(5)
if(type == "top_airing"):
top_elements = driver.find_elements_by_xpath(top_airing)
elif(type == "top_upcoming"):
top_elements = driver.find_elements_by_xpath(top_upcoming)
elif(type == "top_alltime"):
top_elements = driver.find_elements_by_xpath(top_alltime)
top_list = []
rank = 1
for i in top_elements:
srcset = i.find_element_by_xpath("./p/a/img").get_attribute("data-srcset")
imagesrc = srcset.split(",")[1][:-3]
print(imagesrc)
title = i.find_element_by_xpath("./div/h3/a").text
top_list.append(AnimeEntry(title, imagesrc, rank))
rank += 1
driver.quit()
return top_list