Вы можете использовать селекторы *
in css, которые соответствуют части значения в определенном атрибуте.
from bs4 import BeautifulSoup
html = """
<div id="document_64219">
<div id="part_12">
<p class="keywords_HTAG">
<strong> Key Words : </strong>
<ol>
<li>first</li>
<li>second</li>
</ol>
</p>
<ol>
<li>third</li>
<li>fourth</li>
</ol>
"""
soup = BeautifulSoup(html, 'html.parser')
# if you want the li with in the div with the id contains part_
# This will return first , second , third and fourth
lis = [li.text for li in soup.select('div[id*="part_"] li')]
print('All li ==>',lis)
# if you want olny the li with in the div with the id contains part_ and with in the p tag only
# This will return first , second
lis = [li.text for li in soup.select('div[id*="part_"] p.keywords_HTAG li')]
print('with in p only ==>',lis)
# if you want olny the li with in the div with the id contains part_ and without the li in the p tag
# This will return third and fourth
lis = [li.text for li in soup.select('div[id*="part_"] > ol li')]
print('without li in p ==>',lis)
Выход:
All li ==> ['first', 'second', 'third', 'fourth']
with in p only ==> ['first', 'second']
without li in p ==> ['third', 'fourth']