Skip to content

Commit 5af5dd2

Browse files
Merge pull request #92 from Vincebye/master
Add setting web request proxy option
2 parents 8f70a8b + 52b73f0 commit 5af5dd2

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Here are a few examples of how to use `paramspider`:
6060
paramspider -d example.com -s
6161
```
6262

63+
- Set up web request proxy:
64+
65+
```sh
66+
paramspider -d example.com -p '127.0.0.1:7890'
67+
```
6368
## Contributing
6469

6570
Contributions are welcome! If you'd like to contribute to `paramspider`, please follow these steps:

paramspider/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@ def load_user_agents():
3535
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"
3636
]
3737

38-
def fetch_url_content(url):
38+
def fetch_url_content(url,proxy):
3939
"""
4040
Fetches the content of a URL using a random user agent.
4141
Retries up to MAX_RETRIES times if the request fails.
4242
"""
4343
user_agents = load_user_agents()
44-
44+
if proxy is not None:
45+
proxy={
46+
'http':proxy,
47+
'https':proxy
48+
}
4549
for i in range(MAX_RETRIES):
4650
user_agent = random.choice(user_agents)
4751
headers = {
4852
"User-Agent": user_agent
4953
}
5054

5155
try:
52-
response = requests.get(url, headers=headers)
56+
response = requests.get(url, proxies=proxy,headers=headers)
5357
response.raise_for_status()
5458
return response
5559
except (requests.exceptions.RequestException, ValueError):

paramspider/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def clean_urls(urls, extensions):
7878
cleaned_urls.add(cleaned_url)
7979
return list(cleaned_urls)
8080

81-
def fetch_and_clean_urls(domain, extensions, stream_output):
81+
def fetch_and_clean_urls(domain, extensions, stream_output,proxy):
8282
"""
8383
Fetch and clean URLs related to a specific domain from the Wayback Machine.
8484
@@ -92,7 +92,7 @@ def fetch_and_clean_urls(domain, extensions, stream_output):
9292
"""
9393
logging.info(f"{Fore.YELLOW}[INFO]{Style.RESET_ALL} Fetching URLs for {Fore.CYAN + domain + Style.RESET_ALL}")
9494
wayback_uri = f"https://web.archive.org/cdx/search/cdx?url={domain}/*&output=txt&collapse=urlkey&fl=original&page=/"
95-
response = client.fetch_url_content(wayback_uri)
95+
response = client.fetch_url_content(wayback_uri,proxy)
9696
urls = response.text.split()
9797

9898
logging.info(f"{Fore.YELLOW}[INFO]{Style.RESET_ALL} Found {Fore.GREEN + str(len(urls)) + Style.RESET_ALL} URLs for {Fore.CYAN + domain + Style.RESET_ALL}")
@@ -134,6 +134,7 @@ def main():
134134
parser.add_argument("-d", "--domain", help="Domain name to fetch related URLs for.")
135135
parser.add_argument("-l", "--list", help="File containing a list of domain names.")
136136
parser.add_argument("-s", "--stream", action="store_true", help="Stream URLs on the terminal.")
137+
parser.add_argument("-p", "--proxy", help="Set the proxy address for web requests.",default=None)
137138
args = parser.parse_args()
138139

139140
if not args.domain and not args.list:
@@ -153,11 +154,11 @@ def main():
153154
extensions = HARDCODED_EXTENSIONS
154155

155156
if args.domain:
156-
fetch_and_clean_urls(domain, extensions, args.stream)
157+
fetch_and_clean_urls(domain, extensions, args.stream,args.proxy)
157158

158159
if args.list:
159160
for domain in domains:
160-
fetch_and_clean_urls(domain, extensions, args.stream)
161+
fetch_and_clean_urls(domain, extensions, args.stream,args.proxy)
161162

162163
if __name__ == "__main__":
163164
main()

0 commit comments

Comments
 (0)