前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,如有問題請及時聯系我們以作處理,
平時都是直接爬取圖片,但是有些時候只想要個別的圖該怎么辦呢?
專案目標
爬取愛徒網素材下載地址
通過點擊素材進入素材詳情頁,可以看到本地下載地址,多復制幾個素材的下載地址鏈接:
http://www.aiimg.com/sucai.php?open=1&aid=126632&uhash=70a6d2ffc358f79d9cf71392
http://www.aiimg.com/sucai.php?open=1&aid=126630&uhash=99b07c347dc24533ccc1c144
http://www.aiimg.com/sucai.php?open=1&aid=126634&uhash=d7e8f7f02f57568e280190b4
每個鏈接的aid不一樣,這個應該就是素材的每個ID,后面的uhash又是什么呢
原本想著網頁資料里面是否有介面資料可以直接找到這個引數,在開發者工具里面搜索并沒有這個引數,看一下網頁源代碼里面是否有這個下載鏈接~
有這個鏈接的話,咱們獲取鏈接之后就可以直接下載~
常規操作:
1.打開開發者工具,查看網頁是否回傳自己想要獲取的資料,
可以發現,咱們需要的資料都在網頁的標簽里面,請求網頁獲取回傳資料
import requests url = 'http://www.aiimg.com/list.php?tid=1&ext=0&free=2&TotalResult=5853&PageNo=1' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36' } response = requests.get(url=url, headers=headers) print(response.text)
決議爬取資料
import parsel selector = parsel.Selector(response.text) lis = selector.css('.imglist_d ul li a::attr(href)').getall() for li in lis: num_id = li.replace('.html', '').split('/')[-1] new_url = 'http://www.aiimg.com/sucai.php?aid={}'.format(num_id) response_2 = requests.get(url=new_url, headers=headers) selector_2 = parsel.Selector(response_2.text) data_url = selector_2.css('.downlist a.down1::attr(href)').get() title = selector_2.css('.toart a::text').get() download_url = 'http://www.aiimg.com' + data_url
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/158103.html
標籤:其他
上一篇:Python描述器
