-
Notifications
You must be signed in to change notification settings - Fork 0
/
insta_get.py
68 lines (54 loc) · 2.13 KB
/
insta_get.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
from selenium import webdriver
import time, pickle, os
from config import insta_login, insta_pass
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument("--mute-audio")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=chrome_options)
# chrome_options = webdriver.ChromeOptions()
# # chrome_options.add_argument("--headless")
# chrome_options.add_argument("--disable-blink-features=AutomationControlled")
# chrome_options.add_argument("--mute-audio")
# driver = webdriver.Chrome(executable_path=r"drivers/chromedriver111.exe", options=chrome_options)
driver.get(url=r"https://www.instagram.com")
driver.implicitly_wait(3)
for cookie in pickle.load(open(f"login.cookies", "rb")):
driver.add_cookie(cookie)
driver.implicitly_wait(2)
driver.refresh()
print("ishga tayyor !")
def get_data(url):
driver.get(url=url)
# driver.implicitly_wait(2)
return driver.find_element_by_tag_name("pre").get_attribute('innerText')
# return driver.page_source
def login():
try:
print("Dastur ishga tushdi !")
driver.get(url=r"https://www.instagram.com")
driver.implicitly_wait(3)
driver.find_element_by_name("username").send_keys(insta_login)
time.sleep(1)
driver.find_element_by_name("password").send_keys(insta_pass)
time.sleep(1)
driver.find_element_by_css_selector('button[type="submit"]').click()
time.sleep(3)
print("Akkountdamiz !")
pickle.dump(driver.get_cookies(), open(f"login.cookies", "wb"))
print("Login malumotlari saqlandi !")
except Exception as ex:
print('Nimadur xato !')
print(ex)
driver.close()
driver.quit()
print('Dastur tugatildi !')
def driver_down():
driver.close()
driver.quit()
print('Dastur tugatildi !')
if __name__ == '__main__':
login()