-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper3.py
58 lines (48 loc) · 1.75 KB
/
scraper3.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
53
54
55
56
57
58
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import re
import time
import random
def main():
with open("pages.txt", "r") as a_file:
n = a_file.read()
if n.isdigit() != True:
n = 1
driver = webdriver.Firefox()
user = "links"
driver.get(user)
WebDriverWait(driver, 300).until(EC.element_to_be_clickable((By.CLASS_NAME, "uk-position-cover")))
lastpage = driver.find_element(By.CSS_SELECTOR, ".pagination-next").get_attribute("title")
lastpage = re.sub('\\D', '', lastpage)
try:
for i in range(int(n), int(lastpage)+1):
driver.get(str(user[:-1])+str(i))
# time.sleep(5)
time.sleep(random.randrange(1, 3))
WebDriverWait(driver, 9999).until(EC.element_to_be_clickable((By.CLASS_NAME, "uk-position-cover")))
elem = driver.find_elements(By.TAG_NAME, "a")
links = []
for e in elem:
try:
href = e.get_attribute("href")
if "stream?v" in href: links.append(href)
except:
a = 0
ext = "link"
for l in links:
id = l[26:]
url = (str(ext)+str(id)+".mp4")
with open("links.txt", "a") as a_file:
a_file.write(url)
a_file.write("\n")
with open("pages.txt", "w") as a_file:
a_file.write(str(i))
except Exception as e:
print(e)
driver.close()
return
main()