Skip to content

Commit d00e885

Browse files
committed
add sockets proxies
1 parent 5436614 commit d00e885

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python_spider.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
python_spider.py by xianhu
55
"""
66

7+
import requests
78
import urllib.error
89
import urllib.parse
910
import urllib.request
@@ -94,3 +95,12 @@
9495
handler = urllib.request.HTTPBasicAuthHandler(password_mgr) # 创建HTTPBasicAuthHandler
9596
opener = urllib.request.build_opener(handler) # 创建opner
9697
response = opener.open(url, timeout=10) # 获取数据
98+
99+
100+
# 使用Sockets代理
101+
import socks
102+
import socket
103+
104+
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080)
105+
socket.socket =socks.socksocket
106+
requests.get("http://www.baidu.com/s?ie=utf-8&wd=ip")

0 commit comments

Comments
 (0)