搜索
您的当前位置:首页正文

python 爬虫第二步

来源:二三四教育网
  import requests
  res= 
  res.encoding='utf-8'
  #print(res.text)

效果图


图片.png

取出文字

    from  bs4 import  BeautifulSoup

     html_sample=' \
        <html> \
        <body> \
        <h1 id="title"> hello world </h1 >\
          <a href="#" class="link">这是一句话</a> \
         <a href="#" class="link2">这是第二句句话</a> \
      </body>\
     </html>'

     soup = BeautifulSoup(html_sample,'html.parser')
     print(type(soup))
     print(soup.text)
图片.png

拾取元素
1


图片.png

2


图片.png

3

图片.png

4

图片.png

5


图片.png

6

图片.png

7


图片.png

8


图片.png

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

热门图文

Top