【发布时间】:2026-01-03 05:05:03
【问题描述】:
我只需要提取网页中某个部分的链接,但我在 Beautifulsoup 上找到的所有教程总是抓取整个页面。
如何只抓取某个<div class="xyz">内的链接???
编辑: 我目前有这个代码:
soup1.find_all('h3', class_="entry-title td-module-title")
这会找到网页的所有链接,包含在class_="entry-title td-module-title"中
我想找到类中仍然包含的所有链接
"entry-title td-module-title"`
但只有那些包含在由以下部分表示的部分:
<div class="wpb_wrapper">
(对不起,如果我的问题有点缺乏信息,我试图添加更多细节)
【问题讨论】:
-
soup.findAll("div", {"class": "xyz"})这应该可以。稍后您应该通过将其存储在变量中来抓取该部分内的各个链接。 -
这能回答你的问题吗? How to find elements by class
标签: python web-scraping beautifulsoup