1. 程式人生 > >B站相簿小爬蟲

B站相簿小爬蟲

今天下午自閉
終於是沒有什麼困難的寫出了一個自己覺得還行的爬蟲

import requests
import re
heders = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36'
}
def url(number):
    urls = []
    for i in range(number):
        url = 'https://api.vc.bilibili.com/link_draw/v2/Doc/list?category=all&type=hot&page_num={}&page_size=20'.format(i)
        urls.append(url)
    return urls
def getone(num):
    picture_url = []
    for a in url(num):
        i = 0
        res = requests.get(a,headers = heders).text
        wtf = '"img_src":"(.*?)"'
        hahaha = re.findall(wtf,res,re.S)
        for b in hahaha:
            picture_url.append(hahaha[i])
            i = i + 1
    return picture_url
def download(num):
    t = 0
    for a in getone(num):

        www = requests.get(a,headers = heders)
        with open('E:\\for_bilibili_picture\\{}.jpg'.format(t),'wb')as f:
            f.write(www.content)
        t = t + 1
download(20)

有很多東西還是不會功能也很簡單
(誰能想到是因為bilibili模擬登陸不會,才發現Ajax也可以的)
接下來也要準備探索反反爬蟲和昨天說得多線任務了
就像這樣!