爬快代理提供的免费ip代理
2020-07-16 本文已影响0人
chanyi
这是快代理的免费ip访问路径:https://www.kuaidaili.com/free/inha/1/
下面是代码实现
def get_kuai_proxy_ip():
print("开始获取kuai代理免费ip代理")
proxy = []
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Ubuntu Chromium/44.0.2403.89 '
'Chrome/44.0.2403.89 '
'Safari/537.36'}
for i in range(1, 20):
r = requests.get("https://www.kuaidaili.com/free/inha/"+str(i)+"/",
headers=header)
html = r.text
soup = BeautifulSoup(html, "html.parser")
trs = soup.find_all('tr')[1:]
proxy_url = ""
for tr in trs:
tds = tr.find_all("td")
if tds[3].text == "HTTP":
# proxy_url = "http://"+tds[0].text+":"+tds[1].text
proxy_url = tds[0].text+":"+tds[1].text
if tds[3].text == "HTTPS":
# proxy_url = "https://"+tds[0].text+":"+tds[1].text
proxy_url = tds[0].text+":"+tds[1].text
print(proxy_url)
if proxy_url != "":
proxy.append(proxy_url)
return proxy
if __name__ == '__main__':
proxys = get_kuai_proxy_ip()