generated from Hazel/python-project
Compare commits
3 Commits
9f9ce9bd89
...
36829906d0
Author | SHA1 | Date | |
---|---|---|---|
|
36829906d0 | ||
|
186208a2da | ||
|
e9ea63fe5c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -160,3 +160,4 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
cache
|
||||||
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"referer"
|
||||||
|
]
|
||||||
|
}
|
@ -5,6 +5,7 @@ A Python library for simplified HTTP requests, featuring rate limiting, browser-
|
|||||||
## ToDo
|
## ToDo
|
||||||
|
|
||||||
- [ ] basic structure
|
- [ ] basic structure
|
||||||
|
- [ ] caching
|
||||||
- [ ] add cloudscraper
|
- [ ] add cloudscraper
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@ -4,3 +4,5 @@ import pathlib
|
|||||||
__name__ = "python_requests"
|
__name__ = "python_requests"
|
||||||
__folder__ = str(pathlib.Path(__file__).parent)
|
__folder__ = str(pathlib.Path(__file__).parent)
|
||||||
|
|
||||||
|
|
||||||
|
CACHE_DIRECTORY = "cache"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from .connections import Connection
|
||||||
|
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@ -30,5 +32,12 @@ def cli():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
c = Connection()
|
||||||
|
c.generate_headers()
|
||||||
|
print(c.session.headers)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
22
python_requests/connections.py
Normal file
22
python_requests/connections.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
from typing import Optional
|
||||||
|
import requests
|
||||||
|
from urllib.parse import urlparse, urlunsplit, ParseResult
|
||||||
|
|
||||||
|
|
||||||
|
class Connection:
|
||||||
|
def __init__(self, session: Optional[requests.Session] = None) -> None:
|
||||||
|
self.session = session if session is not None else requests.Session()
|
||||||
|
|
||||||
|
def generate_headers(self, referer: Optional[str] = None):
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0",
|
||||||
|
"Connection": "keep-alive",
|
||||||
|
"Accept-Language": "en-US,en;q=0.5",
|
||||||
|
}
|
||||||
|
|
||||||
|
if referer is not None:
|
||||||
|
headers["Referer"] = referer
|
||||||
|
|
||||||
|
self.session.headers.update(**headers)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user