【发布时间】:2020-06-09 20:30:46
【问题描述】:
我一直在努力尝试使用 BeautifulSoup 学习网络抓取。我正在尝试制作一个 Hangman 游戏来学习 Python,并希望制作一个使用英语中最常见的 1000 个单词的单人游戏模式。我最初只是要复制粘贴每个单词并遍历一个列表(这就是为什么会有那个 while 循环),但我决定改用 BeautifulSoup。
import requests
from bs4 import BeautifulSoup
#words = []
#while True:
#word = input("Enter the word: ")
#words.append(word)
#print(words)
page = requests.get("https://www.ef.edu/english-resources/english-vocabulary/top-1000-words/")
resources/english-vocabulary/top-1000-words/")
soup = BeautifulSoup(page.content, "html.parser")
para = soup.find(class_="field-item even")
我不太确定从这里去哪里。我正在尝试将网站中的所有这些项目(甚至位于 feild-item 类的第二段标记中)单独附加到一个列表中,然后将该列表保存为一个包以在主 Hangman 游戏中使用。由于单词出现在第二段标签中,我不知道该怎么做。我观看了一些 YouTube 视频,但它们都处理具有 id 或其他类可调用的文本。谢谢
【问题讨论】:
-
链接是否一分为二?
标签: python beautifulsoup