From e03e8be8ffcb633bd9589abe1cf2f6109427dfe6 Mon Sep 17 00:00:00 2001
From: kathe <110901739+katarzynaheller@users.noreply.github.com>
Date: Thu, 7 Nov 2024 09:28:39 +0100
Subject: [PATCH] [Issue 35] change google as default by adding customizable
url param (#49)
* [Issue-35] fix: expand method with url param to hit custom endpoints
* [Issue-35] fix: update README
* [Issue 35] updated release date
* [Issue 35] update version in setup and readme flag
---
CHANGELOG.md | 4 ++++
README.md | 26 ++++++++++++++++++++++++--
fp/fp.py | 5 +++--
setup.py | 2 +-
test_proxy.py | 8 ++++++++
5 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d461cf7..7d37ca5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## [1.1.3] - 2024-11-07
+
+- Added `url` paramameter
+
## [1.1.2] - 2024-07-29
- Updated lxml to version 5.3.0
diff --git a/README.md b/README.md
index 9118ce7..bcb65e2 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Free-proxy
-![Version 1.1.2](https://img.shields.io/badge/Version-1.1.2-blue.svg)
+![Version 1.1.3](https://img.shields.io/badge/Version-1.1.3-blue.svg)
## Get free working proxies from , , and and use them in your script
@@ -48,7 +48,7 @@ from fp.fp import FreeProxy
| elite | bool | True | False |
| google | bool,None | False | None |
| https | bool | True | False |
-
+| url | str | '' | google.com |
- **No parameters**
Get the first working proxy from . If no proxies are working, try again pulling from
@@ -126,9 +126,27 @@ proxy = FreeProxy(country_id=['US', 'BR'], timeout=0.3, rand=True).get()
If there are no working proxies with the provided parameters, the script will raise `FreeProxyException` with the message `There are no working proxies at this time.`.
+- **`url` parameter**
+ The url parameter allows you to set a custom URL for testing purposes. If left empty, it defaults to 'https://www.google.com'.
+
+Using default URL:
+
+```python
+proxy = FreeProxy().get()
+```
+
+Using custom URL, if test on different endpoint is needed:
+
+```python
+proxy = FreeProxy(url='http://httpbin.org/get').get()
+```
+
## CHANGELOG
---
+## [1.1.3] - 2024-11-07
+
+- Added `url` paramameter
## [1.1.2] - 2024-09-07
@@ -182,6 +200,10 @@ If there are no working proxies with the provided parameters, the script will ra
- Initial release
+## Disclaimer
+
+The authors of this repository are not responsible for any consequences, damages or losses arising from the use or misuse of this repository or content. Users are solely responsible for their actions and any consequences that may follow.
+
## License
---
diff --git a/fp/fp.py b/fp/fp.py
index 7614665..8431a46 100644
--- a/fp/fp.py
+++ b/fp/fp.py
@@ -18,7 +18,7 @@ class FreeProxy:
working proxy.
'''
- def __init__(self, country_id=None, timeout=0.5, rand=False, anonym=False, elite=False, google=None, https=False):
+ def __init__(self, country_id=None, timeout=0.5, rand=False, anonym=False, elite=False, google=None, https=False, url='https://www.google.com'):
self.country_id = country_id
self.timeout = timeout
self.random = rand
@@ -26,6 +26,7 @@ def __init__(self, country_id=None, timeout=0.5, rand=False, anonym=False, elite
self.elite = elite
self.google = google
self.schema = 'https' if https else 'http'
+ self.url = url
def get_proxy_list(self, repeat):
try:
@@ -87,7 +88,7 @@ def get(self, repeat=False):
'There are no working proxies at this time.')
def __check_if_proxy_is_working(self, proxies):
- url = f'{self.schema}://www.google.com'
+ url = f'{self.schema}://{self.url}'
ip = proxies[self.schema].split(':')[1][2:]
with requests.get(url, proxies=proxies, timeout=self.timeout, stream=True) as r:
if r.raw.connection.sock and r.raw.connection.sock.getpeername()[0] == ip:
diff --git a/setup.py b/setup.py
index 23eda8e..cb6362b 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
long_description = fh.read()
setuptools.setup(
name='free_proxy',
- version='1.1.2',
+ version='1.1.3',
author="jundymek",
author_email="jundymek@gmail.com",
description="Proxy scraper for further use",
diff --git a/test_proxy.py b/test_proxy.py
index f001ad3..7b678fe 100644
--- a/test_proxy.py
+++ b/test_proxy.py
@@ -118,6 +118,14 @@ def default_page_second_loop(self):
actual = subject._FreeProxy__website(repeat=True)
self.assertEqual('https://free-proxy-list.net', actual)
+ def test_default_url(self):
+ proxy =FreeProxy()
+ self.assertEqual(proxy.url, 'https://www.google.com')
+
+ def test_custom_url(self):
+ proxy = FreeProxy(url='http://httpbin.org/get')
+ self.assertEqual(proxy.url, 'http://httpbin.org/get')
+
def __tr_elements(self):
return lh.fromstring(
''