0
これは、与えられた単語のための便利なコンテキスト文を提供wordinastence.comから必要な情報をクロールし、解析するために私のコードです:私は指定されたメソッドを実行した場合BS4 select()メソッド
#first import request to crawl the html from the target page
#this case the website is http://www,wordinasentence.com
import requests
target = input("The word you want to search : ")
res = requests.get("https://wordsinasentence.com/"+ target+"-in-a-sentence/")
#further, put this in so that res_process malfunction could flag the errors
try:
res.raise_for_status()
except Exception as e:
print("There's a problem while connecting to a wordsinasentence sever:", e)
#it's a unreadable information, so that we needs to parse it to make it readable.
## use the beautifulsoup to make it readable
import bs4
html_soup = bs4.BeautifulSoup(res.text, 'html.parser')
#check it has been well parsed
#now we'll extract the Defintion of target
keywords = html_soup.select('Definition')
は '(定義のそれぞれで独立し選択します「)、それは空のリストにもhtml_soup変数をプリントアウトし次のように何も返さない保つ:
<p onclick='responsiveVoice.speak("not done for any particular reason; chosen or done at random");' style="font-weight: bold; font-family:Arial; font-size:20px; color:#504A4B;padding-bottom:0px;">Definition of Arbitrary</p>
[]
可能な問題でしょうか?