! /usr/bin/python
from Tkinter import *
import re from bs4 import BeautifulSoup import urllib2
openweb = "https://en.wikipedia.org/wiki/" def button(): sen = str(entry.get()) sen_new = sen.rstrip() sen_new = sen_new.replace(" ", "_") search = openweb + sen_new html_page = urllib2.urlopen(search) soup = BeautifulSoup(html_page, "html.parser") for link in soup.findAll('a', attrs={'href': re.compile("^http://")}): print link.get('href')
def getLinks(url):
html_page = urllib2.urlopen(url)
soup = BeautifulSoup(html_page, "html.parser")
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
return link.get('href')
def getTitle(url0):
soup1 = BeautifulSoup(urllib2.urlopen(url0), "html.parser")
return soup1.title.string.strip()
link_list = []
title_list = []
def getarrayLinks(url2):
html_page = urllib2.urlopen(url2)
soup2 = BeautifulSoup(html_page, "html.parser")
for link0 in soup2.findAll('a', attrs={'href': re.compile("^http://")}):
var = link0.get('href')
try:
Title = getTitle(var)
link_list.append(var)
title_list.append(Title)
# print Title
except urllib2.URLError as t:
continue
except AttributeError as e:
# pop invalid url
continue
sen = str(str(entry.get()))
sen_new = sen.rstrip()
sen_new = sen_new.lstrip()
static_link = "https://en.wikipedia.org/wiki/"
sen_new1 = sen_new.replace(" ", "_")
search = static_link + sen_new1
getLinks(search)
getarrayLinks(search)
All_list = zip(title_list, link_list)
L = [x[0] for x in All_list]
L1 = [x[1] for x in All_list]
length = len(All_list)
print " Title Link: "
print (180 * "-")
w = 0
for w in range(length):
# print '%-10s --- %-10s' % (L[w], L1[w])
print str(w + 1) + ".- " + L[w] + "----------" + L1[w]
root = Tk()
root.title("Credible Resource Utility (CRU)")
frame1 = Frame(root)
frame1.pack()
bottomframe1 = Frame(root)
bottomframe1.pack()
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
mylist = Listbox(root, yscrollcommand=scrollbar.set)
for w in range(length):
mylist.insert(END, str(w + 1) + ".- " + L[w] + "----------" + L1[w])
mylist.pack(side=LEFT, fill=BOTH, expand=True)
scrollbar.config(command=mylist.yview)
root.mainloop()
Log in or sign up for Devpost to join the conversation.