I want to crawl data from website X with url Y
I have token from response login. I tried to use request by Postman with that token then it worked.
So I want to write a function to call that url Y but when I run the application with fastapi.
The requests will be stopped by the CORS from the website.
How can I pass the CORS from that website to get the response?
`def get_data_from_url(url, token):
try:
headers = {“Authorization”: f”Bearer {token}”}
response = requests.get(url, headers=headers, verify=False)
if response.status_code == 200:
return response.json() # Trả về dữ liệu dưới dạng JSON
else:
print(f”Failed to fetch data from {url}. Status code: {response.status_code}”)
return None
except requests.exceptions.RequestException as e:
print(f”An error occurred while fetching data from {url}: {e}”)
return None
@router.get(‘/crawl’)
def export_csv():
token = “eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIwMzA1MjYwMzA5IiwidHlwZSI6MiwiZXhwIjoxNzE0MDM5NDQyLCJpYXQiOjE3MTM5NTMwNDJ9.hahZP-PYegMotDNyEqBxjGKWCJCvh37-j07i2maDbuT7jz0uD625Ej9rYw7g1P6FdbHXKGGNquQ6iXs5WoqgEw”
data = get_data_from_url(“https://linkurl”, token)
return data
`
I want to get response from this web