-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbrowser.py
More file actions
73 lines (63 loc) · 3.42 KB
/
browser.py
File metadata and controls
73 lines (63 loc) · 3.42 KB
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
71
72
73
# ----------------------------------------------------------------------------------------------------
# Authur: creativeJoe007
# Github: https://github.com/creativeJoe007/instagram-leads-scraper
# Website: https://creativejoe007.com
#----------------------------------------------------------------------------------------------------
# An instagram bot that allows anyone search for businesses/influencers using a keyword
# We extract the business name, profile picture, email (if any), mobile number (if any), followers,
# followings, total posts, bio, profile-link and website (if any)
#----------------------------------------------------------------------------------------------------
# Ideal for people looking for leads/prospects on Instagram
# Also ideal for those looking for influencers in certain fields to promote their brands
#----------------------------------------------------------------------------------------------------
from selenium import webdriver
from webdriver_manager.utils import ChromeType
from webdriver_manager.firefox import GeckoDriverManager
from selenium.common.exceptions import WebDriverException
def determine_browser(preferred_browser="chrome", binary_path=""):
#----------------------------------------------------------------------------------------------
# We would perform try and catch for multiple browser type until we find one that exits
# ON the host system
#----------------------------------------------------------------------------------------------
supported_browser = ["chrome", "chromium"]
try:
if preferred_browser not in supported_browser:
return f"This browser is not supported by this library, only supported browsers are {supported_browser}"
else:
if preferred_browser == "chrome" or preferred_browser == "chromium":
return start_chrome(preferred_browser, binary_path)
except WebDriverException as e:
return f"Browser error: {str(e)}"
except OSError as e:
return f"OS Error: {str(e)}"
def start_chrome(_preferred_type, binary_path):
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from webdriver_manager.utils import ChromeType
options = Options()
options.add_argument('--headless')
options.add_argument('start-maximized')
options.add_argument("enable-automation")
options.add_argument("--disable-extensions")
options.add_argument("--window-size=1920,8000");
options.add_argument("enable-features=NetworkServiceInProcess");
options.add_argument("disable-features=NetworkService");
options.add_argument("--no-sandbox")
options.add_argument("--disable-infobars")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--force-device-scale-factor=1")
# If binary path was passed
if binary_path: options.binary_location=binary_path
if _preferred_type == "chrome":
return webdriver.Chrome(ChromeDriverManager().install(), options=options)
else:
return webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install(), options=options)
def start_firefox(binary_path):
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_headless()
binary = FirefoxBinary(binary_path)
return webdriver.Firefox(firefox_binary=binary, options=options)