Skip to content

Commit fdc6454

Browse files
committed
feat: modify the example
1 parent b767f89 commit fdc6454

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

main.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
playwright_install,
99
add_download_options
1010
)
11-
from scrapegraph_py import ScrapeGraphClient, smart_scraper
11+
from scrapegraph_py import SyncClient
12+
from scrapegraph_py.logger import get_logger
1213

1314
st.set_page_config(page_title="Scrapegraph-ai demo", page_icon="🕷️")
1415

1516
# Install playwright browsers
1617
playwright_install()
1718

19+
# Initialize logger
20+
get_logger(level="DEBUG")
21+
1822
def save_email(email):
1923
with open("mails.txt", "a") as file:
2024
file.write(email + "\n")
@@ -48,15 +52,20 @@ def save_email(email):
4852
prompt = st.text_input('Enter your prompt:')
4953

5054
# Initialize client with the input API key
51-
client = ScrapeGraphClient(api_key)
55+
client = SyncClient(api_key=api_key)
5256

5357
# When the user clicks the 'Scrape' button
5458
if st.button('Scrape'):
5559
try:
56-
result = smart_scraper(client, url, prompt)
57-
st.write(result)
60+
response = client.smartscraper(
61+
website_url=url,
62+
user_prompt=prompt
63+
)
64+
st.write(response['result'])
5865
except Exception as e:
5966
st.write(f"Error: {str(e)}")
67+
finally:
68+
client.close()
6069

6170

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

scrapegraph_py_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)