python - 无法使用 for 循环从网站获取定义列表
问题描述
这里是 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)
解决方案
article.find('div', class_='wod-definition-container').p.text
只返回拳头
. 像这样试试。
for s in soup.find_all('article')[0].find('div', class_='wod-definition-container').find_all('p'):
print(s.text)
推荐阅读
- makefile - libtool 安装在本地,configure.ac 期间没有 AC_PROG_LIBTOOL
- javascript - Navigo.js 仅适用于本地主机
- python - Python:如何反转字符串的多个切片操作
- node.js - node-libxml-xsd 在进行 node-gyp 重建时失败,并显示“...xmljs.node:文件无法识别:文件格式无法识别”
- html - justify-content: flex-start 不工作
- ios - Xcode 错误(无法创建配置文件)
- javascript - 在矩阵中寻找邻居并将其存储
- javascript - 无法在 python Jupyter 笔记本中合并 d3
- python - 将我自己的文件命名为与模块相同的名称后无法导入 Python 模块
- php - Laravel 5.5 通过 gmail 发送电子邮件,从数据库配置