Beiyou Python Programming and practice – Crawler learning

Time:2022-1-3

Video addressClick here

Douban reading list collection code

import requests

Station B hot list collection code

import requests
import csv

hot_list = []
page = 1
while 1:
    page_url = f"https://api.bilibili.com/x/web-interface/popular?ps=20&pn={page}"
    print(page_url)
    res = requests.get(page_url)
    json_content = res.json()
    for item in json_content['data']['list']:
        hot_list.append([
            item['bvid'],
            item['pic'],
            item['title'],
            item['owner']['name']
        ])

    page += 1
    if page > 11:
        break

with open('bilibili.csv', 'w', encoding='utf-8', newline='') as f:
    csv_writer = csv.writer(f)
    csv_writer.writerows(hot_list)

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Thank you for reading. If you have any harvest, you might as well like it: smiling_ imp: