-
Notifications
You must be signed in to change notification settings - Fork 1
/
snaptik.py
70 lines (54 loc) · 2.01 KB
/
snaptik.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
59
60
61
62
63
64
65
66
67
68
69
70
import random
import time
import requests
from pathlib import Path
from selenium.webdriver import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import file_process
import init
def gate(chrome):
url = ['https://snaptik.app/en', 'https://snaptik.app/in',
'https://snaptik.app/th', 'https://snaptik.app/ID', 'https://snaptik.app/cs']
master = open('link/master.txt', 'r')
links = master.read().splitlines()
used_links = []
error_links = []
for link in links:
chrome.get(url[random.randrange(5)])
inputbar = WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="url"]'))
)
button = WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="submiturl"]'))
)
try:
inputbar.send_keys(link)
button.click()
try:
download = WebDriverWait(chrome, 30).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="download-block"]/div/a[2]'))
)
except:
print('載入影片檔逾時')
href = download.get_attribute('href')
chrome.get(href)
file_process.rename()
used_links.append(link)
except Exception as e:
print(e)
error_links.append(link)
with open('link/master.txt', 'w') as f:
for link in error_links:
f.write(link+'\n')
with open('link/used.txt', 'r') as f:
old_links = f.read().splitlines()
used_links += old_links
with open('link/used.txt', 'w') as f:
for link in used_links:
f.write(link+'\n')
if __name__ == '__main__':
chrome = init.guise_chrome()
gate(chrome)