browser-dog 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Chandler Song
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.1
2
+ Name: browser_dog
3
+ Version: 0.0.1
4
+ Summary: chrome selenium browser by cookies
5
+ Home-page: https://www.linkedin.com/in/chandlersong/
6
+ Author: chandler song
7
+ Author-email: 275737875@qq.com
8
+ License: MIT
9
+ Keywords: selenium automation browser cookies
10
+ Platform: all
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Natural Language :: Chinese (Simplified)
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+
22
+ # Introduction
23
+ ## Install package
24
+ ```shell
25
+ pip install browser_dog
26
+ ```
27
+ ## Preparation
28
+
29
+ - create file `linkedin_cookies.json`
30
+
31
+ - please use Chrome Extension `EditThisCookie` to export linkedin cookies to `linkedin_cookies.json`
32
+
33
+ ## Example Usage:
34
+
35
+ ```python
36
+ from browser_dog.browser import BrowserDog
37
+
38
+ cat = BrowserDog('cookie.json', 'https://gitee.com', headless=True)
39
+ driver = cat.get_driver()
40
+
41
+ driver.get("https://gitee.com/login")
42
+ cat.long_wait()
43
+
44
+ # Get HTML
45
+ html = driver.page_source
46
+
47
+ ```
@@ -0,0 +1,26 @@
1
+ # Introduction
2
+ ## Install package
3
+ ```shell
4
+ pip install browser_dog
5
+ ```
6
+ ## Preparation
7
+
8
+ - create file `linkedin_cookies.json`
9
+
10
+ - please use Chrome Extension `EditThisCookie` to export linkedin cookies to `linkedin_cookies.json`
11
+
12
+ ## Example Usage:
13
+
14
+ ```python
15
+ from browser_dog.browser import BrowserDog
16
+
17
+ cat = BrowserDog('cookie.json', 'https://gitee.com', headless=True)
18
+ driver = cat.get_driver()
19
+
20
+ driver.get("https://gitee.com/login")
21
+ cat.long_wait()
22
+
23
+ # Get HTML
24
+ html = driver.page_source
25
+
26
+ ```
File without changes
@@ -0,0 +1,98 @@
1
+ import time
2
+ import random
3
+ from selenium import webdriver
4
+ from selenium.webdriver.chrome.options import Options
5
+ import json
6
+ import os
7
+ from colorama import Fore, Style
8
+
9
+ class BrowserDog:
10
+ def __init__(self, cookies_json: str, base_url: str, headless=False):
11
+ """
12
+ Initializes the Chrome Driver.
13
+ """
14
+ try:
15
+ print(Fore.BLACK + "=" * 30 + " Initializing Driver " + "=" * 30 + Style.RESET_ALL)
16
+ # use local selenium driver
17
+ self.options = Options()
18
+ # headless mode
19
+ if headless:
20
+ self.options.add_argument("--headless")
21
+ self.driver = webdriver.Chrome(options=self.options)
22
+
23
+ # use docker selenium/standalone-chrome
24
+ # selenium_grid_url = 'http://localhost:4444/wd/hub'
25
+ # option = Options()
26
+ # option.set_capability("browserName", "chrome")
27
+ # option.set_capability("platformName", "Linux")
28
+ # print('Initialize selenium')
29
+ # self.driver = webdriver.Remote(command_executor=selenium_grid_url, options=option)
30
+
31
+ self.driver.maximize_window()
32
+ print(Fore.GREEN + "Opening URL Page: " + base_url + Style.RESET_ALL)
33
+ self.driver.get(base_url)
34
+ self.medium_wait()
35
+
36
+ if not os.path.exists(cookies_json):
37
+ print(Fore.RED + "No cookies file found, please login first, default: cookies.json " + Style.RESET_ALL)
38
+ else:
39
+ with open(cookies_json, 'r') as file:
40
+ cookies = json.loads(file.read())
41
+
42
+ for cookie in cookies:
43
+ cookie['sameSite'] = "None"
44
+ self.driver.add_cookie(cookie)
45
+
46
+ print(Fore.GREEN + "Refreshing the page to apply cookies" + Style.RESET_ALL)
47
+ self.driver.refresh()
48
+ self.medium_wait()
49
+ print(Fore.GREEN + "Successfully login the website, please start browsering..." + Style.RESET_ALL)
50
+ except Exception as e:
51
+ print(Fore.RED + f'Error: {e}' + Style.RESET_ALL)
52
+
53
+ def get_driver(self):
54
+ return self.driver
55
+
56
+ def scroll_to_bottom(self):
57
+ """
58
+ Scrolls to the bottom of the page.
59
+ """
60
+ self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
61
+
62
+ def scroll_to_top(self):
63
+ """
64
+ Scrolls to the top of the page.
65
+ """
66
+ self.driver.execute_script("window.scrollTo(0, 0);")
67
+
68
+ def scroll_to_middle(self):
69
+ """
70
+ Scrolls to the middle of the page.
71
+ """
72
+ self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);")
73
+
74
+ def scroll_to_random(self):
75
+ """
76
+ Scrolls to a random position of the page.
77
+ """
78
+ self.driver.execute_script("window.scrollTo(0, Math.floor(Math.random() * document.body.scrollHeight));")
79
+
80
+ def short_wait(self):
81
+ """
82
+ Sleeps for a random amount of time between 1 and 3 seconds.
83
+ """
84
+ time.sleep(random.randint(1, 3))
85
+
86
+ def medium_wait(self):
87
+ """
88
+ Sleeps for a random amount of time between 3 and 5 seconds.
89
+ """
90
+ time.sleep(random.randint(3, 5))
91
+
92
+ def long_wait(self):
93
+ """
94
+ Sleeps for a random amount of time between 5 and 10 seconds.
95
+ """
96
+ time.sleep(random.randint(5, 10))
97
+
98
+
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.1
2
+ Name: browser-dog
3
+ Version: 0.0.1
4
+ Summary: chrome selenium browser by cookies
5
+ Home-page: https://www.linkedin.com/in/chandlersong/
6
+ Author: chandler song
7
+ Author-email: 275737875@qq.com
8
+ License: MIT
9
+ Keywords: selenium automation browser cookies
10
+ Platform: all
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Natural Language :: Chinese (Simplified)
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+
22
+ # Introduction
23
+ ## Install package
24
+ ```shell
25
+ pip install browser_dog
26
+ ```
27
+ ## Preparation
28
+
29
+ - create file `linkedin_cookies.json`
30
+
31
+ - please use Chrome Extension `EditThisCookie` to export linkedin cookies to `linkedin_cookies.json`
32
+
33
+ ## Example Usage:
34
+
35
+ ```python
36
+ from browser_dog.browser import BrowserDog
37
+
38
+ cat = BrowserDog('cookie.json', 'https://gitee.com', headless=True)
39
+ driver = cat.get_driver()
40
+
41
+ driver.get("https://gitee.com/login")
42
+ cat.long_wait()
43
+
44
+ # Get HTML
45
+ html = driver.page_source
46
+
47
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ browser_dog/__init__.py
5
+ browser_dog/browser.py
6
+ browser_dog.egg-info/PKG-INFO
7
+ browser_dog.egg-info/SOURCES.txt
8
+ browser_dog.egg-info/dependency_links.txt
9
+ browser_dog.egg-info/requires.txt
10
+ browser_dog.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ selenium
2
+ colorama
@@ -0,0 +1 @@
1
+ browser_dog
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ from distutils.core import setup
2
+ from setuptools import find_packages
3
+ with open("README.md", "r",encoding='utf-8') as f:
4
+ long_description = f.read()
5
+ setup(name='browser_dog', # 包名
6
+ version='0.0.1', # 版本号
7
+ description='chrome selenium browser by cookies',
8
+ long_description_content_type = 'text/markdown',
9
+ long_description=long_description,
10
+ author='chandler song',
11
+ author_email='275737875@qq.com',
12
+ url='https://www.linkedin.com/in/chandlersong/',
13
+ keywords = "selenium automation browser cookies",
14
+ license='MIT',
15
+ packages = find_packages(),
16
+ install_requires=[
17
+ "selenium",
18
+ "colorama",
19
+ ],
20
+ platforms=["all"],
21
+ classifiers=[
22
+ 'Intended Audience :: Developers',
23
+ 'Operating System :: OS Independent',
24
+ 'Natural Language :: Chinese (Simplified)',
25
+ 'Programming Language :: Python :: 3.7',
26
+ 'Programming Language :: Python :: 3.8',
27
+ 'Programming Language :: Python :: 3.9',
28
+ 'Programming Language :: Python :: 3.10',
29
+ 'Topic :: Software Development :: Libraries'
30
+ ],
31
+
32
+ )