问题描述
解决方案
您可以使用.find_previous('h4')
:
import requests
from bs4 import BeautifulSoup
url = "https://french.kwiziq.com/revision/grammar"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
for a in soup.select(".callout li > a:nth-of-type(1)"):
print(
"{:<70} {}".format(
a.get_text(strip=True), a.find_previous("h4").get_text(strip=True)
)
)
印刷:
Saying your name: Je m'appelle, Tu t'appelles, Vous vous appelez A0: Pronouns
Tu and vous are used for three types of you A0: Pronouns
Je becomes j' with verbs beginning with a vowel (elision) A0: Verbs Tenses & Conjugation
J'habite à [city] = I live in [city] A0: Idioms, Idiomatic Usage, and Structures
Je viens de + [city] = I'm from + [city] A0: Idioms, Idiomatic Usage, and Structures
Conjugate être (je suis, tu es, vous êtes) in Le Présent (present tense) A0: Verbs Tenses & Conjugation
Make most adjectives feminine by adding -e A0: Adjectives & Adverbs
Nationalities differ depending on whether you're a man or a woman (adjectives) A0: Adjectives & Adverbs
Conjugate avoir (j'ai, tu as, vous avez) in Le Présent (present tense) A0: Verbs Tenses & Conjugation
Using un, une to say "a" (indefinite articles) A0: Nouns & Articles
...
French vocabulary and grammar lists by theme C1: Idioms, Idiomatic Usage, and Structures
French Fill-in-the-Blanks Tests C1: Idioms, Idiomatic Usage, and Structures
推荐阅读
- kotlin - Kotlin:无法在 Arraylist 中找到元素
- excel - 一种在合并单元格中查找字符串的方法
- python - 如何测试不同格式的日期和日期时间?
- javascript - 如何根据属性移动类
- powershell - 如何运行“Get-Command”返回的所有 cmdlet?
- c# - 为什么四分之三的非常相似的 ajax 调用作为帖子工作,而第四个只作为 get 工作?
- r - 添加语言选项时,带有单选按钮的 R Shiny DT 会中断
- java - 具有固定大小线程池的 ExecutorService - 如何阻止添加任何更多任务,直到池大小有空间
- python - 如何将熊猫数据框按其自身的一个小节划分?
- python - Quandl 仅返回从 2018 年 3 月 27 日到现在的请求的空数据帧