Код: Выделить всё
Some terms: Foo
Some details.
With Bar term.
Код: Выделить всё
import bs4
from bs4 import BeautifulSoup
from sys import argv
with open(argv[1], 'r') as f:
example_s = f.read()
soup = BeautifulSoup(example_s, 'html.parser')
# 1 the correct selection:
print("Correct:", soup.select("div.foo div.node dfn"))
div = soup.select_one("div.foo")
# 2 incorrect, does not match 1:
sel = div.select("div.node dfn")
print("Div:", div)
print("Incorrect:", sel)
print(bs4.__version__)
Код: Выделить всё
Correct: [Bar]
Div:
Some terms: Foo
Some details.
With Bar term.
Incorrect: [Foo, Bar]
4.14.3
Подробнее здесь: https://stackoverflow.com/questions/798 ... -correctly
Мобильная версия