Skip to content

Commit

Permalink
fix[html]: handle requests in case of referrer (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArslanSaleem authored Oct 7, 2024
1 parent 11d4af1 commit f906d35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ def fetch_html_and_save(url, file_path):

headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/58.0.3029.110 Safari/537.3"
)
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) "
"Gecko/20100101 Firefox/91.0"
),
"Referer": url,
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
}

response = requests.get(url, headers=headers)
session = requests.Session()
response = session.get(url, headers=headers)
response.raise_for_status()
# Get the content of the response

# Save the content to a file
with open(file_path, "wb") as file:
file.write(response.content)

0 comments on commit f906d35

Please sign in to comment.