Last active
December 4, 2019 17:51
-
-
Save coxtor/fc65157d2c538d4983f9722e26e3b79a to your computer and use it in GitHub Desktop.
Selenium script for placing free udemy corses from e.g. mydealz into udemy shopping cart. Purchase and login still has to occur manually - very basic script.
This file contains hidden or 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
''' | |
Very basic Selenium script for placing free udemy corses from an url source e.g. mydealz into udemy shopping cart. | |
Purchase and login still has to occur manually. | |
1. Enter base url - may have to change things in for future runs | |
2. Run the script - watch out for captchas | |
3. Login | |
4. "buy" the courses in cart | |
''' | |
from selenium import webdriver | |
from tbselenium.tbdriver import TorBrowserDriver | |
from time import sleep | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support.expected_conditions import * #presence_of_element_located | |
base_url = "https://www.mydealz.de/deals/kostenlose-udemy-kurse-in-der-ubersicht-1489094" | |
tbb_path= "path to tor" | |
tbb_log_path="path to log" | |
#driver = TorBrowserDriver(tbb_path, tbb_logfile_path=tbb_log_path) # use this if you dont want captchas | |
driver = webdriver.Chrome() | |
driver.get(base_url) | |
elems = driver.find_elements_by_xpath("//ul/li/a[@href]") | |
urls= [] | |
for elem in elems: | |
if "threaddesc" in elem.get_attribute("href"): | |
urls.append(elem.get_attribute("href")) | |
print "Got " + str(len(urls)) + " urls" | |
for elem in urls: | |
driver.get(elem) | |
driver.implicitly_wait(90) | |
if("Free" in driver.find_element_by_css_selector(".buy-box__element [data-purpose='course-price-text']").get_attribute("innerHTML")): | |
try: | |
print str(driver.find_element_by_css_selector("[data-purpose='lead-title']").get_attribute("innerHTML")) + " is free" | |
driver.find_element_by_css_selector("[data-purpose='add-to-cart']").click() | |
except: | |
print "Error with url " + elem | |
#driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment