我正在试着从西班牙-英语词典中提取拼音字母。
例如,当搜索búsqueda时,它的拼音字母表将是(boos-keh-dah)。
但是在我运行.py之后,结果它只显示了[]。
为什么会这样呢?我怎么才能修复它?
下面是我写的代码:
import requests
from bs4 import BeautifulSoup
base_url = "https://www.spanishdict.com/translate/"
search_keyword = input("input the keyword : ")
url = base_url + search_keyword + "&start="
spanishdict_r = requests.get(url)
spanishdict_soup = BeautifulSoup(spanishdict_r.text, 'html.parser')
print(spanishdict_soup.findAll('dictionaryLink--369db'))发布于 2020-01-08 17:19:25
首先,删除"&start="。它不会加载期望的结果。所以URL应该是url = base_url + search_keyword。
其次,转换出现在<span class="dictionaryLink--369db">中,这是一个具有class值dictionaryLink--369db的span标记。因此,您的搜索应该是spanishdict_soup.find('span', {'class': 'dictionaryLink--369db'})。
代码:
import requests
from bs4 import BeautifulSoup
base_url = "https://www.spanishdict.com/translate/"
search_keyword = 'búsqueda'
url = base_url + search_keyword
spanishdict_r = requests.get(url)
spanishdict_soup = BeautifulSoup(spanishdict_r.text, 'html.parser')
print(spanishdict_soup.find('span', {'class': 'dictionaryLink--369db'}).text)输出:
(boos-keh-dah)https://stackoverflow.com/questions/59642456
复制相似问题