Reputation: 1
I would like to know how to make a python script that can take outputs from websites. More specifically, get synonyms of a word at the very least and then get pictures of those synonyms if it is possible.
I have tried this piece of code:
import webbrowser
synonyms = []
word = input("what word?")
webbrowser.open('http://thesaurus.com')
But I do not know how to put the word
into the search bar or take the output from that. I have also never tried using images in python. I don't even know if it's possible.
Thank you for your time.
Upvotes: 0
Views: 60
Reputation: 1510
It seems thesaurus website calls an API url when it searchs the synonyms so you can directly call the API with your word and extract a list of synonyms like this :
import requests
word = input("what word?")
url = "https://tuna.thesaurus.com/pageData/" + word
r = requests.get(url)
dict_synonyms = r.json()['data']['definitionData']['definitions'][0]['synonyms']
synonyms = [r["term"] for r in synonyms]
print(synonyms)
The API answers a JSON with many other information so I just selected the synonyms.
Upvotes: 1
Reputation: 43
You can search word by using link https://www.thesaurus.com/browse/<your word>
. Requesting this link using GET method will return page with synonyms.
You can capture screenshot of page by converting html text to png using imgkit for example. But it may look different with original page due to javascript code on the page. Alternatively you can use selenium framework. It acts as browser and able to save page screens.
Upvotes: 0