Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scrapy_proxies/randomproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def __init__(self, settings):
self.proxy_list = settings.get('PROXY_LIST')
self.chosen_proxy = ''

proxy_pattern = '(\w+://)([^:]+?:.+@)?(.+)'
if self.mode == Mode.RANDOMIZE_PROXY_EVERY_REQUESTS or self.mode == Mode.RANDOMIZE_PROXY_ONCE:
if self.proxy_list is None:
raise KeyError('PROXY_LIST setting is missing')
self.proxies = {}
fin = open(self.proxy_list)
try:
for line in fin.readlines():
parts = re.match('(\w+://)([^:]+?:[^@]+?@)?(.+)', line.strip())
parts = re.match(proxy_pattern, line.strip())
if not parts:
continue

Expand All @@ -61,7 +62,7 @@ def __init__(self, settings):
elif self.mode == Mode.SET_CUSTOM_PROXY:
custom_proxy = settings.get('CUSTOM_PROXY')
self.proxies = {}
parts = re.match('(\w+://)([^:]+?:[^@]+?@)?(.+)', custom_proxy.strip())
parts = re.match(proxy_pattern, custom_proxy.strip())
if not parts:
raise ValueError('CUSTOM_PROXY is not well formatted')

Expand Down