Created
April 2, 2023 17:23
-
-
Save maakuth/30bf84f2e561d9e678fb708036658a25 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
""" | |
Yksinkertainen Long Playn epubien noutovempele. | |
Tarvitaan Python, Selenium, Firefox ja Geckodriver | |
Testatut versiot: | |
- Python 3.11.2 | |
- Selenium 4.8.3 | |
- Geckodriver 0.32.2 (https://github.com/mozilla/geckodriver) | |
- Firefox 111.0.1 | |
Kirjaudu Longplay.fi:hin selaimella, ota noiden kahden cookien arvo selaimestasi ja sijoita ne noihin | |
muuttujiin tuossa alla. Sitten vain ajelet. En ole kyllä varma tarvitaanko refresh_tokenia, mutta | |
samapa kai se. | |
""" | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
import selenium.common.exceptions | |
driver = webdriver.Firefox() | |
driver.get("https://www.longplay.fi/") | |
cookies = [ | |
{ | |
'name': 'auth.access_token.local', | |
'value': "Keksin arvo tähän" | |
}, | |
{ | |
'name': 'auth.refresh_token.local', | |
'value': "Keksin arvo tähän" | |
} | |
] | |
for cookie in cookies: | |
driver.add_cookie(cookie) | |
driver.get("https://www.longplay.fi/pitkat") | |
driver.implicitly_wait(1) | |
while(True): | |
try: | |
morelink = driver.find_element(By.XPATH, '//button[text()="Lisää pitkiä juttuja"]') | |
if morelink.is_displayed: | |
morelink.click() | |
except selenium.common.exceptions.NoSuchElementException: | |
break | |
article_urls = [] | |
for article_link in driver.find_elements(By.CLASS_NAME, "read-more"): | |
article_urls.append(article_link.get_property("href")) | |
driver.implicitly_wait(6) | |
for article_url in article_urls: | |
driver.get(article_url) | |
driver.find_element(By.XPATH, '//div[text()="Lataa"]').click() | |
driver.find_element(By.PARTIAL_LINK_TEXT, 'Lataa ekirja').click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment