(Amateur writes like that.) Hi, I ’m Nagamasa Yamada. I tried the last one on Window It ’s a program with a great feeling of force. Please ** look with warm eyes **
I will write with the ** premise I know ** of all Last time ↓ https://qiita.com/yamadanagamasa/items/3752e5849ff3b6344348
reference https://qiita.com/Joachim_Sgr/items/d16951ed71eb7da3cb2d The one I used VS code
qiita.rb
#Module import
import os, tkinter, tkinter.filedialog, tkinter.messagebox
from bs4 import BeautifulSoup
import urllib
import urllib.parse
import requests
def func():
rrr= []
global value
print("in the function =",EditBox1.get())
value = EditBox1.get()
m = value
print(m)
m = urllib.parse.quote(value)
#sennbonn
url =f'https://dictionary.goo.ne.jp/srch/all/{m}/m0u/'
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0",
}
#re = urllib.request.Request(url, headers=headers)
print(url)
re = requests.get(url)
#html = urllib.request.urlopen(re)
soup = BeautifulSoup(re.text, 'html.parser')
a = soup.select('#NR-main-in > section:nth-child(2) > div > div.example_sentence > ul > li:nth-child(1) > a > p.text')
print(a, "a")
for x in a:
rrr.append(x.text)
g = "".join(rrr)
print(g)
answer = tkinter.Label(text=g,bg="white")
answer.place(x=20,y=100)
#Window
root = tkinter.Tk()
root.title(u"window dictonary")
root.geometry("400x300")
#Data number input
Static1 = tkinter.Label(text=u'Words you want to look up')
Static1.place(x=5,y=5)
EditBox1 = tkinter.Entry(width=10)
EditBox1.place(x=100, y=5)
b = tkinter.Button(text='search', command=func)
b.pack()
root.mainloop()
print("value=",value) #Confirm that the data has been stored
There are various prints, but these are not necessary. Mostly for confirmation. I have a text box or Window in tkinter I forcibly put the previous one in func ().
(the end) It may be confusing, but thank you for reading.
Recommended Posts