Skip to content

Commit

Permalink
[Issue 35] change google as default by adding customizable url param (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
katarzynaheller authored Nov 7, 2024
1 parent c7538ec commit e03e8be
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <https://www.sslproxies.org/>, <https://www.us-proxy.org/>, <https://free-proxy-list.net/uk-proxy.html> and <https://free-proxy-list.net> and use them in your script

Expand Down Expand Up @@ -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 <https://www.sslproxies.org/>. If no proxies are working, try again pulling from <https://free-proxy-list.net>

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

---
Expand Down
5 changes: 3 additions & 2 deletions fp/fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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
self.anonym = anonym
self.elite = elite
self.google = google
self.schema = 'https' if https else 'http'
self.url = url

def get_proxy_list(self, repeat):
try:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Proxy scraper for further use",
Expand Down
8 changes: 8 additions & 0 deletions test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<tr>'
Expand Down

0 comments on commit e03e8be

Please sign in to comment.