-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added post method, as get was failing on me. #57
Open
lewis-morris
wants to merge
1
commit into
Nv7-GitHub:master
Choose a base branch
from
lewis-morris:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+335
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,213 @@ | ||
import random | ||
import secrets | ||
|
||
def _get_useragent(): | ||
""" | ||
Returns a random user agent | ||
|
||
def get_useragent(): | ||
return random.choice(_useragent_list) | ||
Returns: | ||
str: Random user agent | ||
|
||
|
||
_useragent_list = [ | ||
""" | ||
return random.choice([ | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', | ||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0' | ||
] | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.54', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_4_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15', | ||
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 OPR/77.0.4054.275', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0 OPR/77.0.4054.277', | ||
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', | ||
'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.54', | ||
'Mozilla/5.0 (Windows NT 6.1; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.1; rv:88.0) Gecko/20100101 Firefox/88.0', | ||
'Mozilla/5.0 (Windows NT 10.0; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; rv:88.0) Gecko/20100101 Firefox/88.0', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.54', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_4_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15', | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15', | ||
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 OPR/77.0.4054.275', | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0 OPR/77.0.4054.277', | ||
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | ||
'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:89.0) Gecko/20100101 Firefox/89.0', | ||
'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko']) | ||
|
||
def _get_referer(): | ||
""" | ||
Returns a random referer | ||
|
||
Returns: | ||
str: Random referer | ||
|
||
""" | ||
return random.choice(["https://www.google.com", | ||
"https://www.bing.com", | ||
"https://www.yahoo.com", | ||
"https://www.duckduckgo.com", | ||
"https://www.facebook.com", | ||
"https://www.twitter.com", | ||
"https://www.instagram.com", | ||
"https://www.linkedin.com", | ||
"https://www.reddit.com", | ||
"https://www.stackoverflow.com", | ||
"https://www.amazon.com", | ||
"https://www.ebay.com", | ||
"https://www.netflix.com", | ||
"https://www.youtube.com", | ||
"https://www.twitch.tv", | ||
"https://www.microsoft.com", | ||
"https://www.apple.com", | ||
"https://www.github.com", | ||
"https://www.wikipedia.org", None, None, None, None, None, None, None, None, None, None, None, | ||
None, None, None, None, None, None, None, None]) | ||
|
||
|
||
def _get_cookies(): | ||
""" | ||
Returns a random cookie string | ||
|
||
Returns: | ||
str: Random cookie string | ||
|
||
""" | ||
no = random.randint(2, 5) | ||
secrets.token_urlsafe(random.randint(8, 15)) | ||
choices = random.choices([f"_ga=GA1.3.{random.randint(100000, 999999)}.{random.randint(100000, 999999)};", | ||
f"_ga=GA1.2.{random.randint(100000, 999999)}.{random.randint(100000, 999999)};", | ||
"_gat=1;", | ||
f"__utma={random.randint(100000, 999999)}.{random.randint(100000, 999999)}.{random.randint(100000, 999999)}.1;", | ||
f"__utmb={random.randint(100000, 999999)}.1.10.{random.randint(100000, 999999)};", | ||
f"__utmc={random.randint(100000, 999999)};", | ||
f"__utmz={random.randint(100000, 999999)}.{random.randint(100000, 999999)}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);", | ||
f"__utmt={random.randint(1, 6)};", | ||
f"session={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f"user_session={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f"remember_user_token={secrets.token_urlsafe(random.randint(2, 5))}.1234-5678;", | ||
f"_csrf_token={secrets.token_urlsafe(random.randint(5, 10))};", | ||
f"JSESSIONID={secrets.token_urlsafe(random.randint(6, 9))};", | ||
f"login={secrets.token_urlsafe(random.randint(8, 15))}", | ||
f"username={randomname._get_name};", | ||
f"__RequestVerificationToken={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f"ASP.NET_SessionId={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f".AspNet.ApplicationCookie={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f"AWSALB={secrets.token_urlsafe(random.randint(8, 15))};", | ||
f"AWSALBCORS={secrets.token_urlsafe(random.randint(8, 15))};"], k=no) | ||
return ",".join(choices) | ||
|
||
|
||
def _get_accept(): | ||
|
||
""" | ||
Returns a random accept string | ||
|
||
Returns: | ||
|
||
""" | ||
return random.choice(["text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | ||
"text/html,application/xhtml+xml;q=0.9,image/webp,image/apng,*/*;q=0.8", | ||
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp;q=0.8,*/*;q=0.7", | ||
"text/html,application/xhtml+xml;q=0.9,image/apng,image/*,*/*;q=0.8", | ||
"text/html,application/xhtml+xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/xml;q=0.7", | ||
"text/html,application/xhtml+xml;q=0.8,image/webp,image/apng,*/*;q=0.7,application/xml;q=0.6", | ||
"text/html,application/xhtml+xml;q=0.8,image/apng,image/*,*/*;q=0.7,application/xml;q=0.6", | ||
"text/html,application/xhtml+xml;q=0.7,image/webp,image/apng,*/*;q=0.8,application/xml;q=0.6", | ||
"text/html,application/xhtml+xml;q=0.7,image/webp;q=0.8,image/apng,*/*;q=0.7,application/xml;q=0.6", | ||
"text/html,application/xhtml+xml;q=0.6,image/webp,image/apng,*/*;q=0.8,application/xml;q=0.7"]) | ||
|
||
|
||
def _get_language(): | ||
|
||
""" | ||
Returns a random language string | ||
|
||
Returns: | ||
str: Random language string | ||
""" | ||
return random.choice(["en-GB,en;q=0.9", | ||
"en-GB,en;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5", | ||
"en-GB,en-US;q=0.9,en;q=0.8", | ||
"en-GB;q=0.9,en;q=0.8,es;q=0.7", | ||
"en-GB,en;q=0.8,fr;q=0.7", | ||
"en-GB;q=0.9,en;q=0.8,fr;q=0.7,de;q=0.6", | ||
"en-GB;q=1.0,en;q=0.9,fr;q=0.8,de;q=0.7,es;q=0.6", | ||
"en-GB;q=1.0,en;q=0.9,es;q=0.8", | ||
"en-GB;q=1.0,en-US;q=0.9,en;q=0.8,fr;q=0.7,de;q=0.6", | ||
"en-GB;q=1.0,en;q=0.9,es;q=0.8,fr;q=0.7"]) | ||
|
||
|
||
def _get_enconding(): | ||
""" | ||
Returns a random encoding string | ||
|
||
Returns: | ||
str: Random encoding string | ||
""" | ||
return random.choice(["gzip, deflate, br, *", | ||
"br, gzip, *", | ||
"gzip, deflate, *", | ||
"*" | ||
"br, *", | ||
"compress, gzip, *", | ||
"gzip, *", | ||
"deflate, br, *", | ||
"gzip, deflate, br, identity, *"]) | ||
|
||
|
||
def get_random_header(): | ||
""" | ||
Returns a random header for a request | ||
""" | ||
# Get random user agent, referer, cookies, accept, language and encoding | ||
user_agent = _get_useragent() | ||
referer = _get_referer() | ||
cookies = _get_cookies() | ||
accept = _get_accept() | ||
language = _get_language() | ||
encoding = _get_enconding() | ||
# Create header | ||
header = {"User-Agent": user_agent, | ||
"Accept": accept, | ||
"Accept-Language": language, | ||
"Accept-Encoding": encoding, | ||
"Cookies": cookies} | ||
# Add referer if it exists | ||
if referer: | ||
header["Referer"] = referer | ||
|
||
return header |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does requests not already do this?