-
Notifications
You must be signed in to change notification settings - Fork 3
/
Selenium.py
68 lines (54 loc) · 2.18 KB
/
Selenium.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
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import pandas as pd
import os
import requests
import shutil
import time
if("Pictures" not in os.listdir(".")):
os.mkdir("Pictures")
proxies = {
'http': 'http://172.16.114.19:3128',
'https': 'https://172.16.114.19:3128',
}
PROXY_HOST = "172.16.114.112"
PROXY_PORT = 3128
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.ftp", PROXY_HOST)
profile.set_preference("network.proxy.ftp_port", PROXY_PORT)
profile.set_preference("network.proxy.https", PROXY_HOST)
profile.set_preference("network.proxy.https_port", PROXY_PORT)
profile.set_preference("network.proxy.socks", PROXY_HOST)
profile.set_preference("network.proxy.socks_port", PROXY_PORT)
profile.set_preference("network.proxy.ssl", PROXY_HOST)
profile.set_preference("network.proxy.ssl_port", PROXY_PORT)
# profile.set_preference("network.proxy.socks_username", "username")
# profile.set_preference("network.proxy.socks_password", "password")
profile.update_preferences()
data = pd.read_csv("Names.csv")
br = webdriver.Firefox(firefox_profile=profile)
for i in range(len(data)):
name = data["Name"][i].split(',')[1][1:] + " " + data["Name"][i].split(',')[0]
print("Working for " + name)
print("//img[@title='" + name + "']")
br.get(data['url'][i])
try:
element = WebDriverWait(br, 10).until(EC.presence_of_element_located((By.XPATH, "//img[@title='" + name + "']")))
image_url = br.find_element_by_xpath("//img[@class='player-img']").get_attribute("src")
name = br.find_element_by_xpath("//img[@class='player-img']").get_attribute("title")
print(image_url)
br.get(data['url'][i])
page = br.page_source.encode('utf-8')
file = open("Webpages/Thrash/" + name + '.html', 'w')
file.write(page)
file.close()
except:
continue
br.quit()