allow Requests to specify a useragent
This commit is contained in:
parent
1b44b58aca
commit
77f50187c5
1 changed files with 4 additions and 3 deletions
|
@ -29,7 +29,7 @@ def url_sanitise(url: str):
|
||||||
url = url[:-1]
|
url = url[:-1]
|
||||||
return url
|
return url
|
||||||
|
|
||||||
USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
|
DEFAULT_USERAGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
|
||||||
"(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36")
|
"(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36")
|
||||||
|
|
||||||
RESPONSE_MAX = (1024*1024)*100
|
RESPONSE_MAX = (1024*1024)*100
|
||||||
|
@ -62,7 +62,7 @@ class Request(object):
|
||||||
detect_encoding: bool=True,
|
detect_encoding: bool=True,
|
||||||
|
|
||||||
parser: str="lxml", fallback_encoding="iso-8859-1",
|
parser: str="lxml", fallback_encoding="iso-8859-1",
|
||||||
content_type: str=None, proxy: str=None,
|
content_type: str=None, proxy: str=None, useragent: str=None,
|
||||||
|
|
||||||
**kwargs):
|
**kwargs):
|
||||||
self.set_url(url)
|
self.set_url(url)
|
||||||
|
@ -81,6 +81,7 @@ class Request(object):
|
||||||
self.fallback_encoding = fallback_encoding
|
self.fallback_encoding = fallback_encoding
|
||||||
self.content_type = content_type
|
self.content_type = content_type
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
|
self.useragent = useragent
|
||||||
|
|
||||||
if kwargs:
|
if kwargs:
|
||||||
if method == "POST":
|
if method == "POST":
|
||||||
|
@ -98,7 +99,7 @@ class Request(object):
|
||||||
if not "Accept-Language" in headers:
|
if not "Accept-Language" in headers:
|
||||||
headers["Accept-Language"] = "en-GB"
|
headers["Accept-Language"] = "en-GB"
|
||||||
if not "User-Agent" in headers:
|
if not "User-Agent" in headers:
|
||||||
headers["User-Agent"] = USER_AGENT
|
headers["User-Agent"] = self.useragent or DEFAULT_USERAGENT
|
||||||
if not "Content-Type" in headers and self.content_type:
|
if not "Content-Type" in headers and self.content_type:
|
||||||
headers["Content-Type"] = self.content_type
|
headers["Content-Type"] = self.content_type
|
||||||
return headers
|
return headers
|
||||||
|
|
Loading…
Reference in a new issue