Skip to content

Commit

Permalink
URLHeadBear: fake the user agent
Browse files Browse the repository at this point in the history
A random fake user agent is used to request webpages
that do not allow bot visits.

Fixes #1203
  • Loading branch information
Akhelesh committed Feb 19, 2019
1 parent 7ecfaa4 commit 5d00e26
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bears/general/URLHeadBear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from urllib.parse import urlparse
from fake_useragent.fake import UserAgent

from bears.general.URLBear import URLBear, LINK_CONTEXT

Expand Down Expand Up @@ -82,8 +83,9 @@ def check_prerequisites(cls):
@staticmethod
def get_head_response(url, timeout):
try:
headers = {'User-Agent': UserAgent().random}
head_resp = requests.head(url, allow_redirects=False,
timeout=timeout)
headers=headers, timeout=timeout)
return head_resp
except requests.exceptions.RequestException as exc:
return exc
Expand Down

0 comments on commit 5d00e26

Please sign in to comment.