【发布时间】:2021-05-09 06:21:52
【问题描述】:
谁能帮助我理解这种现象?如果标签只有一个,'find' 将返回 None。 (我已经尝试过'lxml',但没有帮助)。这是我在 IDE 中所做和接收的部分内容:
>>> driver = webdriver.Chrome("D:\\Text documents\\for work\\English project\\chromedriver")
>>> driver.get('https://www.interactive-english.ru/uprazhneniya/408-conditionals-exercise/')
>>> content = driver.page_source
>>> soup = BeautifulSoup(content, 'lxml')
>>> FullList = soup.findAll(['ol', 'h4', 'h5']);
>>> htmlF = FullList[1]
>>> htmlF
<ol>
<li>
Perhaps one day a cat will follow you home.<br />
What would you do...
</li>
<li>
Perhaps one day somebody will ask you to sing your favourite song.<br />
What would you do...
</li>
<li>
Perhaps one day you will find a hidden treasure.<br />
What would you do...
</li>
<li>
Perhaps one day somebody will throw an egg at you.<br />
What would you do...
</li>
<li>
Perhaps one day your car will be stolen.<br />
What would you do...
</li>
</ol>
>>> print(htmlF.find('li'))
<li>Perhaps one day a cat will follow you home.<br/>What would you do...</li>
>>> print(htmlF.find('ol'))
None
>>>
【问题讨论】:
-
展示如何创建 htmlF。如果它是基于显示的 html 的汤对象,我无法将其复制为正常工作。
-
QHarr,谢谢你的回答。我已经编辑了我的问题。
标签: python html css python-3.x beautifulsoup