【发布时间】:2020-04-01 09:26:38
【问题描述】:
这里是python的新手。我正在尝试获取当天的词汇以及定义和“你知道吗?”这里的部分https://www.merriam-webster.com/word-of-the-day
知道我错过了什么吗?
到目前为止,我能得到的只有以下内容:
C:\Users\Think\PycharmProjects\wotd\venv\Scripts\python.exe C:/Users/Think/PycharmProjects/wotd/wotd.py
loon
Definition
1 : lout, idler
loon 是单词,后面的行仅是第一个定义。还有3个,但我不能用这种方法得到它们。
感谢您的指导
from bs4 import BeautifulSoup
import requests
sauce = requests.get('https://www.merriam-webster.com/word-of-the-day').text
soup = BeautifulSoup(sauce, 'lxml')
article = soup.find('article')
word = article.find('div', class_='word-and-pronunciation').h1.text
definition = article.find('div', class_='wod-definition-container').h2.text
print(word)
print(definition)
for article in soup.find_all('article'):
defin = article.find('div', class_='wod-definition-container').p.text
print(defin)
【问题讨论】:
标签: python beautifulsoup