天天看點

Crawler:基于requests庫+urllib3庫+僞裝浏覽器實作爬取抖音賬号的資訊資料

輸出結果

更新……

代碼設計

from contextlib import closing

import requests, json, time, re, os, sys, time

import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

headers = {

  'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',

  'accept-encoding': 'gzip, deflate, br',

  'accept-language': 'zh-CN,zh;q=0.9',

  'cache-control': 'max-age=0',

  'upgrade-insecure-requests': '1',

  'user-agent': 'Mozilla/5.0 (Linux; U; Android 5.1.1; zh-cn; MI 4S Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.1.3',

 }

class DouYin(object):

   def __init__(self, width=500, height=300):

       """

       抖音App視訊下載下傳

       # 無頭浏覽器

       chrome_options = Options()

       chrome_options.add_argument(

   def get_video_urls(self, user_id):

       獲得視訊播放位址

       Parameters:

           user_id:查詢的使用者ID

       Returns:

           video_names: 視訊名字清單

           video_urls: 視訊連結清單

           nickname: 使用者昵稱

   def video_downloader(self,video_urls, video_names, watermark_flag=False):

       for i in range(len(video_urls)):

           try:

               video_url = video_urls[i]

   def run(self):

       user_id = input('請輸入ID(例如108561773):')

if __name__ == '__main__':

   douyin = DouYin()

   douyin.run()

繼續閱讀