• python爬虫


    python爬虫 - 代理ip的使用

    import sys
    import time
    import hashlib
    import requests
    import urllib3
    from lxml import etree
    
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    _version = sys.version_info
    
    is_python3 = (_version[0] == 3)
    
    orderno = "ZF20179xxxxxxxxx"
    secret = "3f9c2ecac7xxxxxxxxxxxxxxxx"
    
    ip = "forward.xdaili.cn"
    port = "80"
    
    ip_port = ip + ":" + port
    
    timestamp = str(int(time.time()))              
    string = ""
    string = "orderno=" + orderno + "," + "secret=" + secret + "," + "timestamp=" + timestamp
    
    if is_python3:                          
        string = string.encode()
    
    md5_string = hashlib.md5(string).hexdigest()                
    sign = md5_string.upper()                             
    #print(sign)
    auth = "sign=" + sign + "&" + "orderno=" + orderno + "&" + "timestamp=" + timestamp
    
    #print(auth)
    proxy = {"http": "http://" + ip_port, "https": "https://" + ip_port}
    headers = {"Proxy-Authorization": auth, "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"}
    r = requests.get("http://2000019.ip138.com", headers=headers, proxies=proxy, verify=False,allow_redirects=False)
    r.encoding='utf8'
    print(r.status_code)
    print(r.text)
    if r.status_code == 302 or r.status_code == 301 :
        loc = r.headers['Location']
        print(loc)
        r = requests.get(loc, headers=headers, proxies=proxy, verify=False, allow_redirects=False)
        r.encoding='utf8'
        print(r.status_code)
        print(r.text)
    

      

  • 相关阅读:
    javascript删除JSON元素
    State ,Getter , Mutation , Action , Module
    mutation和action区别
    图片懒加载
    git命令合并分支代码
    vue 项目生产环境下去重console
    rem px pt em (区别)
    npm 安装依赖 以及dependencies 和 devDependencies的区别
    仿百度搜索
    h5页面在移动端需要注意的一些事情
  • 原文地址:https://www.cnblogs.com/iupoint/p/14079093.html
Copyright © 2020-2023  润新知