python3用BeautifulSoup抓取圖片地址


# -*- coding:utf-8 -*-
#python 2.7
#XiaoDeng
#http://tieba.baidu.com/p/2460150866
#抓取圖片地址


from bs4 import BeautifulSoup
import urllib.request


html_doc = "http://tieba.baidu.com/p/2460150866"
req = urllib.request.Request(html_doc)  
webpage = urllib.request.urlopen(req)  
html = webpage.read()


soup = BeautifulSoup(html, 'html.parser')


#抓取圖片地址
#抓取img標簽且class為BDE_Image的所有內容
img_src=soup.findAll("img",{'class':'BDE_Image'})
for img in img_src:
    img=img.get('src')   #抓取src
    print(img)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM