Skip to content

Commit aefa54e

Browse files
committed
fix: imports
1 parent 1280ae3 commit aefa54e

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

main.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def save_email(email):
4141
with cent_co:
4242
st.image("assets/scrapegraphai_logo.png")
4343
st.title('Scrapegraph-api')
44-
st.write("refill at this page")
44+
st.write("### Refill at this page [Github page](https://scrapegraphai.com)")
4545

4646
# Get the API key, URL, prompt, and optional schema from the user
4747
api_key = st.text_input('Enter your API key:')
@@ -51,32 +51,45 @@ def save_email(email):
5151

5252
# When the user clicks the 'Scrape' button
5353
if st.button('Scrape'):
54-
# Set up the headers and payload for the API request
55-
headers = {'Content-Type': 'application/json'}
56-
payload = {
57-
'api_key': api_key,
58-
'url': url,
59-
'prompt': prompt,
60-
'schema': schema
61-
}
62-
63-
# Make the API request
64-
response = requests.post('https://api.scrapegraphai.com/smart_scraper', headers=headers, data=json.dumps(payload))
65-
66-
# If the request was successful
67-
if response.status_code == 200:
68-
# Parse the JSON response
69-
data = response.json()
70-
71-
# Display the extracted data
72-
st.write(data['result'])
73-
74-
# Display the remaining credits
75-
st.write(f"Remaining credits: {data['credits_left']}")
76-
77-
# If the request was unsuccessful
54+
if not api_key.startswith('sgai-'):
55+
st.error("Invalid API key format. API key must start with 'sgai-'")
56+
elif not url:
57+
st.error("Please enter a URL to scrape")
58+
elif not prompt:
59+
st.error("Please enter a prompt")
7860
else:
79-
st.write(f"Error: {response.status_code}")
61+
# Set up the headers and payload for the API request
62+
headers = {
63+
'accept': 'application/json',
64+
'SGAI-APIKEY': api_key,
65+
'Content-Type': 'application/json'
66+
}
67+
68+
payload = {
69+
'website_url': url,
70+
'user_prompt': prompt,
71+
'type': 'object'
72+
}
73+
74+
# Add schema to payload if provided
75+
if schema:
76+
payload['schema'] = schema
77+
78+
try:
79+
response = requests.post(
80+
'https://api.scrapegraphai.com/v1/smartscraper',
81+
headers=headers,
82+
json=payload
83+
)
84+
85+
if response.status_code == 200:
86+
data = response.json()
87+
st.write("Result:", data)
88+
else:
89+
st.error(f"Error: {response.status_code} - {response.text}")
90+
91+
except Exception as e:
92+
st.error(f"Error: {str(e)}")
8093

8194

8295
left_co2, *_, cent_co2, last_co2, last_c3 = st.columns([1] * 18)

requirements.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
pandas>=2.2.2
2-
scrapegraphai==1.12.0
3-
streamlit>=1.0
1+
boto3==1.35.36
2+
langchain_core==0.3.23
3+
pandas==2.2.3
4+
Requests==2.32.3
5+
scrapegraphai==1.33.2
6+
streamlit==1.39.0

0 commit comments

Comments
 (0)