65 Star 351 Fork 182

耿直的小爬虫 / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
爬取66ip代理网站.py 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
import re
import requests
#url='http://www.66ip.cn/9.html'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'
}
def page_get(page):
url = 'http://www.66ip.cn/'+str(page)+'.html'''
respon = requests.get(url, headers=headers).text
#print(respon)
rety=re.compile('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,4}).*?(\d{1,6})',re.S).findall(respon)
#test=[]
u=1
for i in rety:
ip=i[0]+':' + i[1] #+'\n'
#test.append(ip)
proxy=ip
proxies={
'http':'http://'+proxy,
'https':'https://'+proxy
#'https':'https://'+proxy
}
#print(proxies)
print(proxy)
try:
response = requests.get('http://httpbin.org/get', timeout=5, proxies=proxies)
# print(response.text)
# print(response.status_code)
#print('成功%d个' % u, '状态码为:', response.status_code)
if response.status_code == 200:
print('成功%d个' % u, '状态码为:', response.status_code)
er = proxy + '\n'
with open('66代理网IP.txt', 'a+')as x:
x.write(er)
u += 1
except Exception as e:
print('出现错误',e.args)
print(page_get(1))
Python
1
https://gitee.com/testp2y/python_reptilian.git
git@gitee.com:testp2y/python_reptilian.git
testp2y
python_reptilian
Python爬虫
master

搜索帮助