-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirecrawl_scraper.py
39 lines (29 loc) · 1003 Bytes
/
firecrawl_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
import json
# Input: URL to scrape
# API Endpoint and Headers
url = "https://api.firecrawl.dev/v1/scrape"
headers = {
"Authorization": "Bearer fc-xxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json"
}
# Payload
payload = {
"url": input.strip()
}
# Making the POST request
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status() # Raise an error for bad HTTP responses
# Parsing the response JSON
response_data = response.json()
# Check for success and extract markdown
if response_data.get("success") and "markdown" in response_data.get("data", {}):
output = response_data["data"]["markdown"]
print("Markdown content successfully saved to 'output'.")
else:
output = response_data;
print("Failed to retrieve markdown. Response:", response_data)
except requests.exceptions.RequestException as e:
output = str(e);
print(f"An error occurred: {e}")