我與美麗的湯嘗試,我試圖從包含以下類型的段一個HTML文檔的信息:網絡與美麗的湯拼搶給空結果
<div class="entity-body">
<h3 class="entity-name with-profile">
<a href="https://www.linkedin.com/profile/view?id=AA4AAAAC9qXUBMuA3-txf-cKOPsYZZ0TbWJkhgfxfpY&trk=manage_invitations_profile"
data-li-url="/profile/mini-profile-with-connections?_ed=0_3fIDL9gCh6b5R-c9s4-e_B&trk=manage_invitations_miniprofile"
class="miniprofile"
aria-label="View profile for Ivan Grigorov">
<span>Ivan Grigorov</span>
</a>
</h3>
<p class="entity-subheader">
Teacher
</p>
</div>
我用下面的命令:
with open("C:\Users\pv\MyFiles\HTML\Invites.html","r") as Invites: soup = bs(Invites, 'lxml')
soup.title
out: <title>Sent Invites\n| LinkedIn\n</title>
invites = soup.find_all("div", class_ = "entity-body")
type(invites)
out: bs4.element.ResultSet
len(invites)
out: 0
爲什麼find_all返回空的ResultSet對象?
您的建議將不勝感激。
嘗試查看頁面時,您獲取它。如果你在這裏看不到這個'div'標籤,那就意味着這個部分是用'JS'生成的,所以你不能用這種方法刮擦它(你必須使用'selenium')。 – Fejs