I'm currently working on a scraper-sort of program, which will enter a Wikipedia page, and in its current form, will scrape the references from the page.
I'd like to have a gui that will allow the user to input a Wikipedia page. I want the input to be attached to the selectWikiPage
variable, but have had no luck as of far.
Below is my current code.
import requests
from bs4 import BeautifulSoup
import re
from tkinter import *
#begin tkinter gui
def show_entry_fields():
print("Wikipedia URL: %s" % (e1.get()))
e1.delete(0,END)
master = Tk()
Label(master, text="Wikipedia URL").grid(row=0)
e1 = Entry(master)
e1.insert(10,"http://en.wikipedia.org/wiki/randomness")
e1.grid(row=0, column=1)
Button(master, text='Scrape', command=master.quit).grid(row=3, column=0, sticky=W, pady=4)
mainloop( )
session = requests.Session()
selectWikiPage = input(print("Please enter the Wikipedia page you wish to scrape from"))
if "wikipedia" in selectWikiPage:
html = session.post(selectWikiPage)
bsObj = BeautifulSoup(html.text, "html.parser")
findReferences = bsObj.find('ol', {'class': 'references'}) #isolate refereces section of page
href = BeautifulSoup(str(findReferences), "html.parser")
links = [a["href"] for a in href.find_all("a", href=True)]
for link in links:
print("Link: " + link)
else:
print("Error: Please enter a valid Wikipedia URL")
Many thanks in advance.