python抓取网页数据( 就是利用Python阿里云盘资源的资料请关注编程相关文章)

优采云 发布时间: 2022-02-23 07:08

  python抓取网页数据(

就是利用Python阿里云盘资源的资料请关注编程相关文章)

  Python抢阿里云盘资源

  前段时间,阿里云盘风靡一时,大量存储空间被送出。而且阿里云盘下载是无限的,比百度网盘好很多。这两天看到一个第三方网站可以在阿里云盘上搜索资源,但是它的资源没有按时间排序。这种情况会导致已经在队列中很长时间的资源成为过时的资源。小编这里使用python进行爬取和重排。

  

  网页分析

  这个 网站 有两条搜索线:搜索线一和搜索线二。这个 文章 使用第二行搜索。

  

  打开控制面板下的网络,一眼就能看到一个sea.html的get请求。

  

  有几个参数,四个关键参数:

  同样在控制面板中,可以看到网页跳转到阿里云盘获取标题上方的真实链接。使用bs4解析页面上div(class=resource-itemborder-dashed-eee)标签下的a标签得到跳转网盘的地址,解析div下的p标签得到资源日期。

  

  抓取和解析

  首先安装解析页面需要的bs4第三方库。

  pip3 install bs4

  下面是抓取并解析网页的脚本代码,最后按日期降序排序。

<p>import requests

from bs4 import BeautifulSoup

import string

word = input('请输入要搜索的资源名称:')

    

headers = {

    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'

}

result_list = []

for i in range(1, 11):

    print('正在搜索第 {} 页'.format(i))

    params = {

        'page': i,

        'keyword': word,

        'search_folder_or_file': 0,

        'is_search_folder_content': 0,

        'is_search_path_title': 0,

        'category': 'all',

        'file_extension': 'all',

        'search_model': 0

    }

    response_html = requests.get('https://www.alipanso.com/search.html', headers = headers,params=params)

    response_data = response_html.content.decode()

   

    soup = BeautifulSoup(response_data, "html.parser");

    divs = soup.find_all('div', class_='resource-item border-dashed-eee')

    

    if len(divs) 

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线