Created
June 18, 2021 19:25
-
-
Save dimitryzub/a107698e15ede2b7cd1e52d6cdfe6177 to your computer and use it in GitHub Desktop.
baidu_serpapi_scrape_answer_box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, json | |
from serpapi import BaiduSearch | |
def get_answerbox_result(): | |
params = { | |
"engine": "baidu", | |
"q": "coffee", | |
"api_key": os.getenv("API_KEY"), | |
} | |
search = BaiduSearch(params) | |
results = search.get_dict() | |
for result in results['answer_box']: | |
title = result['title'] | |
link = result['link'] | |
displayed_link = result['displayed_link'] | |
english_word = result['english_word'] | |
british = result['british'] | |
american = result['american'] | |
defenitions = result['definitions'][0] # array output | |
print(f'{title}\n{link}\n{displayed_link}\n{english_word}\n{british}\n{american}\n{defenitions}') | |
# Output: | |
''' | |
coffee - 百度翻译 | |
http://www.baidu.com/link?url=JA5gottCkKOdztdz_enXoECH2LfUZwlDRs-ll_E7fa6TXpjY6hQzf1GzPU7gTxHkOTOTFpSm6g_6OlvRNqjjP_ | |
fanyi.baidu.com | |
coffee | |
{'phonetic': '[ˈkɒfi]', 'chinese_character': '英', 'audio_link': 'https://sp0.baidu.com/-rM1hT4a2gU2pMbgoY3K/gettts?lan=uk&text=coffee&spd=2&source=alading'} | |
{'phonetic': '[ˈkɔːfi]', 'chinese_character': '美', 'audio_link': 'https://sp0.baidu.com/-rM1hT4a2gU2pMbgoY3K/gettts?lan=en&text=coffee&spd=2&source=alading'} | |
['n. (烘烤过的)咖啡豆; 咖啡粉; 咖啡(热饮料); 一杯咖啡;'] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment