zoukankan      html  css  js  c++  java
  • mongodb

     1 import json
     2 
     3 import requests
     4 import urllib3
     5 from pymongo import MongoClient
     6 
     7 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
     8 
     9 client = MongoClient('localhost', 27017)
    10 collection = client['all_ip']['ip']
    11 
    12 # ret = collection.find_one({"name": "ronle"})
    13 # print(ret)
    14 
    15 ret = collection.find({}, {"_id": 0, "ip": 1, "port": 1})
    16 proxy_ips = list()
    17 for i in ret:
    18     _ips = json.dumps(i)  # {'ip': '58.118.228.7', 'port': '1080'}
    19     proxy_ips.append(_ips)
    20 # print(proxy_ips)  # ['{"ip": "58.118.228.7", "port": "1080"}']
    21 print(proxy_ips)
    22 
    23 # url = "http://api.ipify.org/"
    24 url = "http://icanhazip.com/"
    25 headers = {
    26     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
    27                   '(KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'
    28 }
    29 
    30 for i in proxy_ips:
    31     ip = json.loads(i)
    32     PROXY_IP = {
    33         'http': 'http://' + ip['ip'] + ":" + ip['port']
    34     }
    35     print(PROXY_IP)
    36     response = requests.get(url, headers=headers, proxies=PROXY_IP, verify=False)
    37     if response.status_code == 200:
    38         print(response.content.decode())
    39     else:
    40         print("无效代理")
  • 相关阅读:
    参数迭代的初始值
    印刷体、手写体公式图片OCR识别转latex
    混合型变量聚类的观点
    算法优化大概的方法
    梯度下降法
    支持向量机-可分的类
    LaTex希腊字母
    红黑树删除操作
    红黑树插入操作
    红黑树
  • 原文地址:https://www.cnblogs.com/ronle/p/10114845.html
Copyright © 2011-2022 走看看