import tkinter as tk
from tkinter import ttk
import bs4 as bs
from bs4 import BeautifulSoup, SoupStrainer
import httplib2
soup = BeautifulSoup('html.parser', features="lxml")
#Creation Objet Tkinter#
window = tk.Tk()
#DefinitionTailleObjet#
window.title("Python Tkinter Text Box")
window.minsize(300,200)
label = ttk.Label(window, text = "Entrez l'URL")
label.grid(column = 0, row = 0)
#DefinitionDeLaTailleObjet#
def Valide():
http = httplib2.Http()
status, response = http.request('nameEntered.get')
for link in bs.BeautifulSoup(response, 'html.parser',parse_only=SoupStrainer('a')):
if link.has_attr('href'):
print(link['href'])
#Alogrithme Derriere le bouton#
name = tk.StringVar()
nameEntered = ttk.Entry(window, width = 50, textvariable = name)
nameEntered.pack
nameEntered.grid(column = 0, row = 1)
button = ttk.Button(window, text = "Validé", command = Valide)
button.grid(column= 0, row = 3)
window.mainloop()
Here is my code; I'm trying to test a site that the user inputs, then it takes all the links one by one and tests one by one if they work or not, but I'm stuck because there's a problem with the var I think. Please help.
Thanks in advance for the answers.
The problem resides in the line
status, response = http.request('nameEntered.get')You are passing here a hard-coded string to the
http.request()-function. Actually, you want to read the content of the textfield, I assume. Therefore, you need to callnameEntered.get()and pass its return value to the functionhttp.requestin the function namedValide, like sostatus, response = http.request(nameEntered.get())More descriptive (but equivalent) is this: