Google's “define: ” through an API?

后端 未结 2 833
轻奢々
轻奢々 2020-12-12 13:30

I want to get the result of searches that use special features in Google, like \"define: [phrase]\" and I can\'t seem to find relevant information about this.

Does a

2条回答
  •  温柔的废话
    2020-12-12 14:20

    from bs4 import BeautifulSoup
    import  requests
    word = "democracy"
    url = 'https://www.google.co.in/search?q=define%20' + word + '#cns=1'
    response = requests.get(url, headers={"user-agent":"Mozilla/5.0(Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0"})
    html = response.content
    final_soup = BeautifulSoup(html,"html5lib")
    everyThing = final_soup.select("div._Jig")
    for line in everyThing:
        print("-",line.text)
    

    I wrote this script to get the definition of a word from google. Hope it helps but its not using any API.

提交回复
热议问题