Skip to content

Commit 7591360

Browse files
committed
Simple web search using google
1 parent 85f65a3 commit 7591360

23 files changed

+641
-0
lines changed

Mini Browser/app.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from flask import *
2+
import bs4 as bs
3+
import requests
4+
import urllib
5+
app = Flask(__name__)
6+
7+
@app.route('/')
8+
def index():
9+
form = Markup(get_page())
10+
return render_template('index.html', form = form)
11+
12+
@app.route('/<string:data>')
13+
def query(data):
14+
data = request.query_string
15+
if str(data)[2:4] == 'ie':
16+
results = get_query(data)
17+
form = get_page()
18+
data = [results[0], Markup(form), Markup(results[1][0])]
19+
return render_template('result.html', data = data)
20+
elif str(data)[2:3]:
21+
return get_site(data)
22+
23+
@app.route("/about")
24+
def about():
25+
return render_template("about.html")
26+
27+
def get_page():
28+
sauce = urllib.request.urlopen("https://www.google.com").read()
29+
soup = bs.BeautifulSoup(sauce, 'lxml')
30+
search_form = [form for form in soup.find_all('form') if form.get('action') == '/search']
31+
return str(search_form[0])
32+
33+
def get_query(data):
34+
url = 'https://www.google.com/search?' + str(data)[2:len(str(data)) - 1]
35+
data = requests.get(url)
36+
soup = bs.BeautifulSoup(data.text, 'lxml')
37+
results = [Markup(result) for result in soup.find_all('div', {'class' : 'g'})]
38+
nav = soup.find_all('table', {'id' : 'nav'})
39+
return [results, nav]
40+
41+
def get_site(data):
42+
data = str(data)[4:].split('&sa')[0]
43+
return redirect(data)
44+
45+
if __name__ == '__main__':
46+
app.run(debug=False)

Mini Browser/requirements.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
beautifulsoup4==4.6.0
2+
bs4==0.0.1
3+
certifi==2018.4.16
4+
chardet==3.0.4
5+
click==6.7
6+
Flask==1.0.2
7+
gunicorn==19.8.1
8+
html5lib==1.0.1
9+
idna==2.7
10+
itsdangerous==0.24
11+
Jinja2==2.10
12+
lxml==4.2.1
13+
MarkupSafe==1.0
14+
requests==2.19.0
15+
six==1.11.0
16+
urllib3==1.23
17+
webencodings==0.5.1
18+
Werkzeug==0.14.1

Mini Browser/static/assets/ajax.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$(document).ready(function(){
2+
$("#getCountry").change(function(){
3+
var country = $("#getCountry :selected").text();
4+
console.log(country);
5+
$.ajax({
6+
url: "/api/" + country,
7+
success: function(result){
8+
var toShow = "<div style='font-size: 18px; color: #102E4A; background: #fff;'>" + "<table class='table' style='width: 500px;'><thead><tr><th colspan=2>Country-Capital<th></tr></thead><tbody><tr><th style='width: 150px;'>Country</th><td>:</td><td style='width: 150px;'>" + country + "</td></tr><tr><th style='width: 150px;'>Capital</th><td>:</td><td style='width: 350px;'>" + result + "</td></tr></tbody></table>" + "</div>";
9+
$("#data").html(toShow);
10+
}
11+
});
12+
});
13+
});
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@font-face {
2+
font-family: BerkshireSwash-Regular;
3+
src: url('BerkshireSwash-Regular.ttf');
4+
}

Mini Browser/static/assets/scripts/jquery.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$(function(){
2+
$("td.fl").css({
3+
"display": 'none'
4+
});
5+
$("input[name='btnG']").prop('value', 'Search The Web');
6+
$("input[name='btnG']").addClass("btn btn-primary");
7+
$("input[name='q']").css({
8+
'padding' : '5px'
9+
});
10+
$("input[name='q']").addClass("form-control");
11+
$("input[name='btnI']").css('display', 'none');
12+
$("td[width='25%']").css({
13+
"width" : 0
14+
}).hide();
15+
$(".VBt9Dc, .hp-xpdbox").css({
16+
"display" : "none"
17+
});
18+
$("a.fl").css({
19+
"display" : "none",
20+
"padding" : "0 2px 0 2px"
21+
});
22+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
var checkStatus;
3+
var element = new Image();
4+
element.__defineGetter__('id', function() {
5+
checkStatus = 'on';
6+
alert("Warning!!!\nYou are trying to open developer tools.\nYou are logging out...")
7+
});
8+
9+
setInterval(function() {
10+
checkStatus = 'off';
11+
console.log(element);
12+
console.clear();
13+
}, 500)

Mini Browser/static/assets/styling/bootstrap/css/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Mini Browser/static/assets/styling/bootstrap/css/select.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)