Python代碼爬取下載應用寶全部APP軟件

前言

本文的文字及圖片來源於網絡,僅供學習、交流使用,不具備任何商業用途,若有問題請及時聯繫咱們以做處理。css

基本環境配置

  • python 3.6
  • pycharm
  • requests
  • parsel

 

 


打開開發者工具分析網頁python

 


你怎麼知道這個就是下載地址呢?網絡

一、選擇一個應用的下載地址
二、打開開發者工具,清空數據,選擇Network
三、點擊當即下載
四、就會發現下載地址app

 

 


把連接地址複製,在網頁源代碼中搜索,查看是否網頁是否有返回該數據工具

  • 有數據: 就能夠直接請求網頁獲取地址;
  • 沒有數據: 那就要在開發這工具裏面找是否有接口數據,而後一步一步在進行分析;

實現效果

 

 

完整代碼

import requests
import parsel

def download(url, title):
    path = 'D:\\python\\demo\\應用寶手機APP軟件\\APP軟件\\' + title + '.apk'
    response = requests.get(url=url, headers=headers)
    with open(path, mode='wb') as f:
        f.write(response.content)
        
for page in range(100, 123):
    url = 'https://sj.qq.com/myapp/category.htm?orgame=1&categoryId={}'.format(page)
    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)
    selector = parsel.Selector(response.text)
    lis = selector.css('.main ul li')
    for li in lis:
        title = li.css('.app-info-desc a:nth-child(1)::text').get()
        apk_url = li.css('.app-info-desc a:nth-child(4)::attr(ex_url)').get()
        print(title, apk_url)
        download(apk_url, title)