Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
import re
|
5 |
+
|
6 |
+
def search_fn(query,count):
|
7 |
+
if count>99:
|
8 |
+
count = 99
|
9 |
+
page = requests.get(f"https://www.google.com/search?q={query}&num={count}")
|
10 |
+
soup = BeautifulSoup(page.content)
|
11 |
+
#links = soup.findAll("a")
|
12 |
+
|
13 |
+
links = soup.findAll("a")
|
14 |
+
file = open("myfile.txt", "w")
|
15 |
+
|
16 |
+
for link in soup.find_all("a",href=re.compile("(?<=/url\?q=)(htt.*://.*)")):
|
17 |
+
out = (re.split(":(?=http)",link["href"].replace("/url?q=","").split("&sa",1)[0]))
|
18 |
+
out = out[0]
|
19 |
+
rr=requests.get(f"{out}")
|
20 |
+
x_opt = (dict(rr.headers).get("x-frame-options"))
|
21 |
+
if x_opt == None:
|
22 |
+
frame_l=f'<div class="container-mee"><div class="put-on-top"><a target="_blank" href="{out}">{out}</a></div><iframe class="responsive-iframe-mee" src="{out}" frameborder="3"></iframe></div>'
|
23 |
+
file.writelines(frame_l)
|
24 |
+
else:
|
25 |
+
pass
|
26 |
+
|
27 |
+
#print(file1.read())
|
28 |
+
print (out)
|
29 |
+
print(dict(rr.headers).get("x-frame-options"))
|
30 |
+
|
31 |
+
file.close()
|
32 |
+
|
33 |
+
with open("myfile.txt", "r") as file1:
|
34 |
+
html_out = file1.read()
|
35 |
+
out = format_t(html_out)
|
36 |
+
return out
|
37 |
+
|
38 |
+
|
39 |
+
def first():
|
40 |
+
out = '''<h1>Loading'''
|
41 |
+
return out
|
42 |
+
|
43 |
+
def test(out):
|
44 |
+
return format_t(f'<div class="container-mee"><div class="put-on-top"><a target="_blank" href="{out}">{out}</a></div><iframe class="responsive-iframe-mee" src="{out}" frameborder="3"></iframe></div>')
|
45 |
+
|
46 |
+
def format_t(inp):
|
47 |
+
|
48 |
+
style = '''
|
49 |
+
.put-on-top{
|
50 |
+
align-contents:center;
|
51 |
+
border-style: solid;
|
52 |
+
border-width: 3px;
|
53 |
+
border-radius: 5px;
|
54 |
+
background: none;
|
55 |
+
padding: 0.5em;
|
56 |
+
margin-top:1em;
|
57 |
+
margin-bottom:0.3em;
|
58 |
+
}
|
59 |
+
.grid-mee {
|
60 |
+
display: flex;
|
61 |
+
flex-direction: row;
|
62 |
+
flex-wrap: wrap;
|
63 |
+
justify-content: space-evenly;
|
64 |
+
align-items: stretch;
|
65 |
+
align-content: space-evenly;
|
66 |
+
}
|
67 |
+
|
68 |
+
.container-mee {
|
69 |
+
|
70 |
+
position: relative;
|
71 |
+
overflow: hidden;
|
72 |
+
width: 48%;
|
73 |
+
height: 60em;
|
74 |
+
margin-top:1em;
|
75 |
+
}
|
76 |
+
/* Then style the iframe to fit in the container div with full height and width */
|
77 |
+
.responsive-iframe-mee {
|
78 |
+
position: relative;
|
79 |
+
top: 0;
|
80 |
+
left: 0;
|
81 |
+
bottom: 0;
|
82 |
+
right: 0;
|
83 |
+
width: 100%;
|
84 |
+
height: 100%;
|
85 |
+
|
86 |
+
}
|
87 |
+
'''
|
88 |
+
out = f'''<!DOCTYPE html>
|
89 |
+
<html lang="en">
|
90 |
+
<head>
|
91 |
+
</head>
|
92 |
+
<style>
|
93 |
+
{style}
|
94 |
+
</style>
|
95 |
+
<body>
|
96 |
+
<div class=grid-mee>
|
97 |
+
{inp}
|
98 |
+
</div>
|
99 |
+
</body>
|
100 |
+
</html>'''
|
101 |
+
return out
|
102 |
+
with gr.Blocks() as app:
|
103 |
+
gr.HTML("""<h1>Interactive Social Media Card Maker</h1>""")
|
104 |
+
gr.HTML("""<h3><b>Step 1:</b> Enter URL to test for Iframe capability</h3>""")
|
105 |
+
with gr.Row():
|
106 |
+
search_box=gr.Textbox(label = "Search",scale=2)
|
107 |
+
num_return=gr.Number(value=20, scale=1)
|
108 |
+
search_btn=gr.Button(scale=1)
|
109 |
+
with gr.Row():
|
110 |
+
input = gr.Textbox(label = "URL")
|
111 |
+
btn = gr.Button()
|
112 |
+
output = gr.HTML("""""")
|
113 |
+
|
114 |
+
search_btn.click(search_fn,[search_box,num_return],output)
|
115 |
+
btn.click(first,None,output).then(test,input,output)
|
116 |
+
app.launch()
|