店播爬取Python脚本

dy_live_reward_info.py 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import requests
  2. import time
  3. from libs.proxy import Proxy
  4. from log.print_log import PrintLog
  5. from libs.en0414 import DouYinApi
  6. class DyLiveRewardInfo:
  7. @staticmethod
  8. def get_data(room_id, retry=0):
  9. while True:
  10. if retry > 10:
  11. break
  12. retry += 1
  13. proxy = Proxy.get()
  14. proxies = {
  15. "http": "http://" + proxy,
  16. "https": "http://" + proxy
  17. }
  18. try:
  19. dou_api = DouYinApi('', proxies)
  20. result = dou_api.register_device()
  21. device_id, iid, udid, openudid, cookie = result['device_id'], result['iid'], result['uuid'], result[
  22. 'openudid'], result['cookie']
  23. dou_api.init_device_ids(device_id, iid, udid, openudid)
  24. params = {
  25. "has_market": "0",
  26. "is_activated": '0'
  27. }
  28. dou_api.comm_get('https://aweme.snssdk.com/service/2/app_alert/?', params)
  29. response_json = dou_api.get_webcast_ranklist(room_id)
  30. if (response_json is not None) and (response_json.get('status_code') == 0):
  31. print('成功:' + room_id)
  32. PrintLog.print('成功:' + room_id)
  33. return response_json
  34. if retry >= 10:
  35. print('失败:' + room_id + '***')
  36. PrintLog.print('失败:' + '***')
  37. return None
  38. retry += 1
  39. return DyLiveRewardInfo.get_data(room_id, retry)
  40. except requests.exceptions.ProxyError as e:
  41. PrintLog.print(
  42. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '代理过期!' + str(e) + '\n'
  43. + room_id + '\n'
  44. + Proxy.proxy_info
  45. )
  46. Proxy.del_proxy(proxy)
  47. pass
  48. except requests.exceptions.ConnectTimeout as e:
  49. PrintLog.print(
  50. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ConnectTimeout!' + str(e) + '\n'
  51. + room_id + '\n'
  52. + Proxy.proxy_info
  53. )
  54. Proxy.del_proxy(proxy)
  55. pass
  56. except Exception as e:
  57. PrintLog.print(
  58. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '请求抛出异常!' + str(e) + '\n'
  59. + room_id
  60. )
  61. pass
  62. if __name__ == "__main__":
  63. room_id = '6955048598123891496'
  64. commodity_detail = DyLiveRewardInfo.get_data(room_id)