小编see*_*345的帖子

如何使用美丽的汤从页面中提取链接

我有一个带有多个 div的HTML 页面,例如:

<div class="post-info-wrap">
  <h2 class="post-title"><a href="https://www.example.com/blog/111/this-is-1st-post/" title="Example of 1st post &#8211; Example 1 Post" rel="bookmark">sample post &#8211; example 1 post</a></h2>
  <div class="post-meta clearfix">

    <div class="post-info-wrap">
      <h2 class="post-title"><a href="https://www.example.com/blog/111/this-is-2nd-post/" title="Example of 2nd post &#8211; Example 2 Post" rel="bookmark">sample post &#8211; example 2 post</a></h2>
      <div class="post-meta clearfix">
Run Code Online (Sandbox Code Playgroud)

我需要使用类 post-info-wrap 获取所有 div 的值我是 BeautifulSoup 的新手

所以我需要这些网址:

我试过了:

import re
import requests
from bs4 import BeautifulSoup

r = requests.get("https://www.example.com/blog/author/abc") 
data = r.content  # Content of response

soup …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup

5
推荐指数
2
解决办法
6484
查看次数

标签 统计

beautifulsoup ×1

python ×1