Nice to meet you This is Nagamasa Yamada. I tried to make a program to look up words using scraping guys I did it with google colaboratory https://colab.research.google.com/notebooks/welcome.ipynb?hl=ja
Create a program to search the meaning of words using python
input ➡ Get information in online dictionary with scraping ➡ Display
python
from bs4 import BeautifulSoup
import urllib
import urllib.parse
#Uenoha is the one that encodes Japanese
g=input()
m= urllib.parse.quote(g)
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",
}
request = urllib.request.Request(url, headers=headers)
html = urllib.request.urlopen(request)
soup = BeautifulSoup(html, 'html.parser')
a = soup.select('div[class="example_sentence"] ul[class="content_list idiom lsize"] p[class="text"]')
for x in a:
print(x.text)
python
from bs4 import BeautifulSoup
import urllib
This is the one you need to scrape
python
import urllib.parse
This is the one you need to encode
python
g=input()
m= urllib.parse.quote(g)
This encodes what you input. I forgot here and it didn't work
python
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",
}
request = urllib.request.Request(url, headers=headers)
html = urllib.request.urlopen(request)
soup = BeautifulSoup(html, 'html.parser')
a = soup.select('div[class="example_sentence"] ul[class="content_list idiom lsize"] p[class="text"]')
for x in a:
print(x.text)
The url of the online dictionary is in the url The word you want to look up is in {m}
python
a = soup.select('div[class="example_sentence"] ul[class="content_list idiom lsize"] p[class="text"]')
This identifies the cousin you want to know.
python
for x in a:
print(x.text)
Now I'm taking out everything in a (the end) It may be difficult to understand because it was my first time writing, but thank you for reading.
Recommended Posts