「python初心者」プロキシIPを取得するサンプルコード
pythonコード:
#coding:utf-8
from bs4 import BeautifulSoup
import requests
import random
def getproxyip():
headers = {
'Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8′,
'Accept-Encoding’:’gzip,deflate,sdch’,
'Host’:’www.ip-adress.com’,
'User-Agent’:’Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0′
}
proxy_url = 'http://www.ip-adress.com/Proxy_Checker/’
proxy_req = requests.get(proxy_url,headers=headers)
proxy_soup = BeautifulSoup(proxy_req.text)
proxy_ip = proxy_soup.find_all('tr’,{'class’:’yellow’})
return proxy_ip[random.randrange(0,4)].td.text