• python ip代理


     1 import random
     2 import urllib.request
     3 from bs4 import BeautifulSoup
     4 import time
     5 
     6 url ='http://www.whatismyip.com.tw/'
     7 for i in range(0,5):
     8     
     9     iplist = ['111.13.7.123:80','117.143.109.152:80','59.127.154.78:80']
    10     proxy_support = urllib.request.ProxyHandler({'http':random.choice(iplist)})
    11     opener=urllib.request.build_opener(proxy_support)
    12     opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36')]
    13     urllib.request.install_opener(opener)
    14 
    15 
    16 
    17 
    18     response = urllib.request.urlopen(url)
    19 
    20     html = response.read().decode('utf-8')
    21 
    22     soup=BeautifulSoup(html,'html.parser')
    23 
    24     a=soup.find_all("script",{"type":"application/json"})
    25 
    26     print(a)
    27     time.sleep(1)

    注意的是要验证代理ip是否可用

    大家可以参考这个网站

    http://www.66ip.cn/yz/

  • 相关阅读:
    array常用方法总结
    .babelrc参数小解
    async/await方法解析
    html5-entities.js消失问题
    h => h(App)解析
    package.json字段简要解析
    body-parser小解
    mongodb中的__v字段
    module.exports与exports
    freemarker判断对象是否为空
  • 原文地址:https://www.cnblogs.com/jjj-fly/p/6882994.html
Copyright © 2020-2023  润新知