店播爬取Python脚本

douyin_scraper_register.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import json
  2. from xlog03 import *
  3. from rds_model.db_redis import DbRedis
  4. from log.print_log import PrintLog
  5. import douyin_class
  6. from libs.proxy import Proxy
  7. redisModel = DbRedis.outer_net_connect()
  8. if __name__ == '__main__':
  9. import warnings
  10. warnings.filterwarnings("ignore")
  11. print('===========注册程序===========')
  12. PrintLog.print('===========注册程序===========')
  13. rkey = 'DOUYIN_REGISTER_QUEUE'
  14. cur_time = int(time.time())
  15. while True:
  16. now_time = int(time.time())
  17. if (now_time - cur_time) > 270:
  18. break
  19. str_time = time.strftime("%H:%M:%S", time.localtime())
  20. try:
  21. llen = redisModel.llen(rkey)
  22. if llen < 50:
  23. # 获取代理
  24. proxy = Proxy.rola_get()
  25. proxies = {
  26. "http": "http://" + proxy,
  27. "https": "http://" + proxy
  28. }
  29. # proxies = {
  30. # "http": "http://lum-customer-c_44eb09ec-zone-data_center:4jme8s5hf9x6@zproxy.lum-superproxy.io:22225",
  31. # "https": "http://lum-customer-c_44eb09ec-zone-data_center:4jme8s5hf9x6@zproxy.lum-superproxy.io:22225"
  32. # }
  33. print(str_time + ' 注册代理:' + str(proxies))
  34. PrintLog.print(str_time + ' 注册代理:' + str(proxies))
  35. douApi = douyin_class.DouYinApi('', proxies)
  36. result = douApi.register_device()
  37. if result['device_id'] == '0':
  38. continue
  39. print(str_time + ' 结果:' + str(result))
  40. PrintLog.print(str_time + ' 结果:' + str(result))
  41. json_data = json.dumps(result)
  42. redisModel.lpush(rkey, json_data)
  43. print(str_time + ' 注册成功')
  44. PrintLog.print(str_time + ' 注册成功')
  45. else:
  46. time.sleep(3)
  47. except Exception as e:
  48. print(str_time + ' 错误:' + str(e))
  49. PrintLog.print(str_time + ' 错误:' + str(e))
  50. continue