-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinc_scraper.py
More file actions
36 lines (32 loc) · 839 Bytes
/
inc_scraper.py
File metadata and controls
36 lines (32 loc) · 839 Bytes
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
# -*- coding: utf-8 -*-
__title__ = "Scraper for ProxyGrablin"
__description__ = "Scrapes proxies from given websites."
__author__ = "DrPython3"
__date__ = "2024-10-03"
__version__ = "0.1"
__contact__ = "https://github.com/DrPython3"
# Needed modules:
import sys
import re
import requests
from inc_etc import logging
# Functions:
def scraper(url):
"""
Scrapes IPs from given URL and returns a list.
:param url: URL to scrape
:return: IP list
"""
ip_regex = r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{1,5}\b"
try:
logging(f"Scraping: {url}")
response = requests.get(url)
response.raise_for_status()
scraped = response.text
ips = re.findall(ip_regex, scraped)
logging(f"Scraped {url} successfully.")
return ips
except requests.RequestException as e:
logging(f"Scraping {e} failed.")
return []
# DrPython3 (C) 2024