niharika17032001 commited on
Commit
101de00
·
1 Parent(s): cf356ad

commmit Dockerfile

Browse files
Files changed (2) hide show
  1. Dockerfile +14 -1
  2. selimium_try.py +12 -20
Dockerfile CHANGED
@@ -1 +1,14 @@
1
- FROM ubuntu:latest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a Python base image with Playwright pre-installed
2
+ FROM python:3.9-slim-buster
3
+
4
+ # Install Playwright and its dependencies
5
+ RUN pip install playwright && playwright install chromium
6
+
7
+ # Set the working directory
8
+ WORKDIR /app
9
+
10
+ # Copy the Python script into the container
11
+ COPY selimium_try.py /app/
12
+
13
+ # Command to run the Python script
14
+ CMD ["python", "selimium_try.py"]
selimium_try.py CHANGED
@@ -1,23 +1,15 @@
1
- import gradio as gr
2
  from playwright.sync_api import sync_playwright
3
 
4
- def get_html_from_url(url):
5
- try:
6
- with sync_playwright() as p:
7
- browser = p.chromium.launch()
8
- page = browser.new_page()
9
- page.goto(url)
10
- html = page.content()
11
- browser.close()
12
- return html
13
- except Exception as e:
14
- return f"Error: {e}"
15
 
16
- iface = gr.Interface(
17
- fn=get_html_from_url,
18
- inputs=gr.Textbox(lines=2, placeholder="Enter URL here..."),
19
- outputs=gr.Textbox(lines=20, placeholder="HTML will appear here..."),
20
- title="URL to HTML Fetcher",
21
- )
22
-
23
- iface.launch(share=True)
 
 
1
  from playwright.sync_api import sync_playwright
2
 
3
+ def get_youtube_html(url="https://www.youtube.com"):
4
+ """Fetches the HTML content of a YouTube page using Playwright."""
5
+ with sync_playwright() as p:
6
+ browser = p.chromium.launch()
7
+ page = browser.new_page()
8
+ page.goto(url)
9
+ html = page.content()
10
+ browser.close()
11
+ return html
 
 
12
 
13
+ if __name__ == "__main__":
14
+ html_content = get_youtube_html()
15
+ print(html_content)