西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
西西首頁 電腦軟件 安卓軟件 電腦游戲 安卓游戲 排行榜 專題合集

python爬取半次元圖片源碼

  • python爬取半次元圖片源碼
  • 軟件大小:1KB
  • 更新時間:2019-07-24 16:41
  • 軟件語言:中文
  • 軟件廠商:
  • 軟件類別:國產(chǎn)軟件 / 免費軟件 / 源碼相關(guān)
  • 軟件等級:3級
  • 應(yīng)用平臺:WinXP, Win7, win8
  • 官方網(wǎng)站:暫無
  • 應(yīng)用備案:
好評:50%
壞評:50%

本類精品

軟件介紹

python爬取半次元圖片源碼,由大神自制的python爬取工具,本源碼針對半次元圖片平臺,可以爬取最新的網(wǎng)站圖片資源,支持自定義保存目錄,非常方便,需要requests庫的支持,想要相關(guān)源碼資源的朋友們不要錯過哦!

python爬取半次元圖片源碼

python爬取半次元圖片源碼說明:

需要安裝requests庫,在運行腳本的文件夾下新建一個img文件夾

源碼也可供大家學(xué)習(xí)和參考。

python爬取半次元圖片源碼一覽:

import requests

import re

url = 'https://bcy.net/coser/toppost100'  # 要進(jìn)行抓取的url

web_url = "https://bcy.net"  # 官方網(wǎng)站

file = 'img/'  # 文件的保存路徑最后加反斜杠

headers = {

    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'

}

# 獲取抓取數(shù)據(jù)頁面

data = requests.get(url, headers=headers).text

wi_url_id = re.findall('<a href=".*?class="db posr ovf"', data)

# 對抓取圖片單獨頁面url進(jìn)行遍歷

for s in wi_url_id:

    wi_id = web_url + s.lstrip('<a href="').rstrip('" class="db posr ovf"')

    n_data = requests.get(wi_id, headers=headers).text  # 獲取單獨的圖片頁面數(shù)據(jù)

    json_data = re.findall('"{.*?}"', n_data)[0].lstrip('"').rstrip('}}"')

    n_http = re.findall('"path.*?w650', json_data)

    # 對圖片url進(jìn)行遍歷

    for b in n_http:

        try:

            img_data = b.lstrip('"path\\":\\"s') + '.image'

            img_url = 'https:/' + img_data.replace('u002F', '').replace('\\\\', '/')

            img = requests.get(img_url, headers=headers).content  # 獲取圖片數(shù)據(jù)

            img_name = img_url.rstrip('.jpg~tplv-banciyuan-w650.image')[-31:]  # 獲取圖片名

            # 對圖片進(jìn)行保存

            with open(file + img_name + '.jpg', 'wb') as f:

                f.write(img)

                print('以保存,圖片url:' + img_url)

        except:

            print('保存失敗')

python爬取相關(guān)視頻:

其他版本下載

發(fā)表評論

昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
查看所有(0)條評論 > 字?jǐn)?shù): 0/500

TOP
軟件下載