# 宣告html變數
html=""""
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters;and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""
# z這里使用BeautifulSoup庫,宣告一個soup,決議html
from bs4 import BeautifulSoup
soup = BeautifulSoup(html,'lxml')
# 這里準備提取html中的head標簽內容,結果回傳none值,我很懵,請問這個為什么回傳none而不是,The Dormouse‘s story
print(soup.head)
# 還有這個soup.p只回傳了<p>"</p>,不科學啊,為什么啊難受。
print(soup.p)
uj5u.com熱心網友回復:
soup = BeautifulSoup(html_doc, 'html.parser')
看范例仔細一點
uj5u.com熱心網友回復:
使用“html.lxml",zhe這里沒錯,只是html的文本里面多出來一個”,導致輸出內容有很多的出入。謝謝哈
我自己搞定了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/89385.html
上一篇:請FPGA大佬看過來
