店播爬取Python脚本

douyin_scraper_register.py 1.8KB

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