Tkinter不需要连接到数据库。错误消息是关于
我使用了一个SEO工具,并试图创建一个GUI应用程序,用户可以在其中输入网站链接。然后,我的list_of_rl((函数将执行以查找所有存在的链接。
```python
def ui_for_website():
app = Tk()
app.title("Scrapper")
app.geometry("300x300")
ui_text=StringVar(app,name="str")
ui_text_label=Label(app,text="Enter your website: ",font=('bold',12),pady=20)
ui_text_label.grid(row=0,column=0)
ui_text_entry=Entry(app,textvariable=ui_text)
ui_text_entry.grid(row=0,column=1)
#onclick=lambda : ui_text_entry.get()
ui_text_button=Button(app,text="Submit",command=lambda : onClick(ui_text_entry,app))
ui_text_button.grid(row=2,column=1)
ui_text=ui_text_entry.get()
print(ui_text)
app.mainloop()
```
这是我的Tkinter UI代码,我要求用户输入。
```python
def onClick(entry,app):
#global website_name
website_name=entry.get()
#print(website_name)
#app.quit()
return website_name
``
这是我的onClick方法,一旦用户点击按钮";提交";。我试图返回值,并将其存储在website_name变量中。
```python
def list_of_url():
url=ui_for_website()
print(url)
urls=session.get(url).html.absolute_links
tree = sitemap_tree_for_homepage(url)
#print(len(tree.all_pages()))
#print(len(tree.pages))
url_list=[]
for page in tree.all_pages():
if ('admin' not in page.url) and (page.url not in url_list):
url_list.append(page.url)
print(len(url_list))
return url_list
```
这个网站名称,我正在这个list_of_rls((方法中访问它。但有一次,tkinter关闭了。这个变量的值变为null,我无法获取该值。
我得到的错误是
Traceback (most recent call last):
File "Indexing.py", line 89, in <module>
list_of_url()
File "Indexing.py", line 42, in list_of_url
urls=session.get(url).html.absolute_links
File "C:Users<username>Anaconda3libsite-packagesrequestssessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "C:Users<username>Anaconda3libsite-packagesrequestssessions.py", line 519, in request
prep = self.prepare_request(req)
File "C:Users<username>Anaconda3libsite-packagesrequestssessions.py", line 462, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:Users<username>Anaconda3libsite-packagesrequestsmodels.py", line 313, in prepare
self.prepare_url(url, params)
File "C:Users<username>Anaconda3libsite-packagesrequestsmodels.py", line 387, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
所以,这让我思考是否需要DB来保留用户输入值。这样即使GUI被破坏或关闭。我将保留用户输入的值。
这是我的完整代码:
```python
from requests_html import HTMLSession
from tkinter import *
from usp.tree import sitemap_tree_for_homepage
session=HTMLSession()
#website_name=''
def onClick(entry,app):
#global website_name
website_name=entry.get()
print(website_name)
#app.quit()
return website_name
def ui_for_website():
app = Tk()
app.title("Scrapper")
app.geometry("300x300")
ui_text=StringVar(app,name="str")
ui_text_label=Label(app,text="Enter your website: ",font=('bold',12),pady=20)
ui_text_label.grid(row=0,column=0)
ui_text_entry=Entry(app,textvariable=ui_text)
ui_text_entry.grid(row=0,column=1)
#onclick=lambda : ui_text_entry.get()
ui_text_button=Button(app,text="Submit",command=lambda : onClick(ui_text_entry,app))
ui_text_button.grid(row=2,column=1)
ui_text=ui_text_entry.get()
print(ui_text)
app.mainloop()
def list_of_url():
url=ui_for_website()
print(url)
urls=session.get(url).html.absolute_links
tree = sitemap_tree_for_homepage(url)
#print(len(tree.all_pages()))
#print(len(tree.pages))
url_list=[]
for page in tree.all_pages():
if ('admin' not in page.url) and (page.url not in url_list):
url_list.append(page.url)
print(len(url_list))
return url_list
```
request
到http的。更具体地说,它来自requests
html库。不涉及数据库。