forked from niklasbuschmann/contrast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selenium_test.py
48 lines (35 loc) · 1.3 KB
/
selenium_test.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
import matplotlib.pyplot as plt
options = Options()
options.page_load_strategy = 'normal'
driver = webdriver.Chrome(options=options)
# Youtube Example
""" driver.get("https://www.youtube.com/results?search_query=tiny+train+models")
results = driver.find_elements(By.ID, 'video-title')
for videoTitle in results:
print(videoTitle.text)
"""
# Spotify global daily charts example
driver.get("https://kworb.net/spotify/country/global_daily.html")
results = driver.find_elements(By.CSS_SELECTOR, ".text.mp")
songTitles = []
""" for songTitle in results:
songTitles.append(songTitle.text)
"""
for i in range(20):
songTitles.append(results[i].text)
results = driver.find_elements(By.XPATH, "//*[@id='spotifydaily']/tbody/tr")
songStreams = []
""" for list in results:
songStreams.append(list.find_element(By.CSS_SELECTOR, ":nth-child(7)").text)
"""
for i in range(20):
songStreams.append(results[i].find_element(By.CSS_SELECTOR, ":nth-child(7)").text)
plt.bar(songTitles, songStreams)
plt.xlabel('Song Titles')
plt.ylabel('Total Streams')
plt.show()