Skip to content

Commit

Permalink
Using user agent file as default - fake-useragent package seems curre…
Browse files Browse the repository at this point in the history
…ntly off (#54)
  • Loading branch information
pgaref authored Oct 19, 2019
1 parent 5322364 commit dd2cf26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion http_request_randomizer/requests/proxy/requestProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, web_proxy_list=[], sustain=False, timeout=5, protocol=Protoco
self.logger = logging.getLogger()
self.logger.addHandler(handler)
self.logger.setLevel(0)
self.userAgent = UserAgentManager()
self.userAgent = UserAgentManager(file=os.path.join(os.path.dirname(__file__), '../data/user_agents.txt'))

#####
# Each of the classes below implements a specific URL Parser
Expand Down
1 change: 1 addition & 0 deletions http_request_randomizer/requests/useragent/userAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

logger = logging.getLogger(__name__)


class UserAgentManager:
def __init__(self, fallback=None, file=None):
self.agent_file = file
Expand Down
7 changes: 5 additions & 2 deletions tests/test_useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def test_last_user_agent(self):
self.assertIsNone(self.uafake.get_last_user_agent())

def test_random_user_agent(self):
self.assertNotEqual(self.uafile.get_random_user_agent(), self.uafile.get_random_user_agent())
self.assertNotEqual(self.uafake.get_random_user_agent(), self.uafake.get_random_user_agent())
count = 0
for i in range(1, 101):
if self.uafile.get_random_user_agent() == self.uafile.get_random_user_agent():
count = count + 1
self.assertNotEqual(count, i)


if __name__ == '__main__':
Expand Down

0 comments on commit dd2cf26

Please sign in to comment.