|
@@ -15,26 +15,25 @@ with open('data.json', 'r') as f:
|
|
|
cookies = jsonData['cookies']
|
|
cookies = jsonData['cookies']
|
|
|
|
|
|
|
|
# 设置代理服务器的 IP 和端口号
|
|
# 设置代理服务器的 IP 和端口号
|
|
|
-socks.set_default_proxy(socks.SOCKS5, "172.16.8.1", 1080)
|
|
|
|
|
|
|
+socks.set_default_proxy(socks.SOCKS5, "you_ip", you_port)
|
|
|
|
|
|
|
|
# 将所有的 TCP 连接都通过代理服务器进行处理
|
|
# 将所有的 TCP 连接都通过代理服务器进行处理
|
|
|
socket.socket = socks.socksocket
|
|
socket.socket = socks.socksocket
|
|
|
|
|
|
|
|
def flushCookie():
|
|
def flushCookie():
|
|
|
|
|
+ # 请求体
|
|
|
reqData = {
|
|
reqData = {
|
|
|
- 'email': 'ftebox@qq.com',
|
|
|
|
|
- 'passwd': '369958Na',
|
|
|
|
|
- 'code': ''
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ # 请求头
|
|
|
headers = {
|
|
headers = {
|
|
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36',
|
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36',
|
|
|
- 'Referer': 'https://www.freewhale.co/auth/login',
|
|
|
|
|
|
|
+ 'Referer': 'you_url',
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
# 发送登录请求
|
|
# 发送登录请求
|
|
|
- response = requests.post('https://www.freewhale.co/auth/login', data=reqData, headers=headers, verify=False)
|
|
|
|
|
|
|
+ response = requests.post('url', data=reqData, headers=headers, verify=False)
|
|
|
# 判断是否登录成功
|
|
# 判断是否登录成功
|
|
|
if response.status_code == 200 and '"ret":1' in response.text:
|
|
if response.status_code == 200 and '"ret":1' in response.text:
|
|
|
global cookies
|
|
global cookies
|
|
@@ -42,19 +41,19 @@ def flushCookie():
|
|
|
# 读取cookie
|
|
# 读取cookie
|
|
|
cookies = response.cookies.get_dict()
|
|
cookies = response.cookies.get_dict()
|
|
|
# 将cookie写入jsonData
|
|
# 将cookie写入jsonData
|
|
|
- jsonData['cookies'] = cookies;
|
|
|
|
|
- flushJson("cookie已刷新!");
|
|
|
|
|
|
|
+ jsonData['cookies'] = cookies
|
|
|
|
|
+ flushJson("cookie已刷新!")
|
|
|
else:
|
|
else:
|
|
|
# 失败就重新登陆
|
|
# 失败就重新登陆
|
|
|
flushCookie();
|
|
flushCookie();
|
|
|
except requests.exceptions.RequestException as e:
|
|
except requests.exceptions.RequestException as e:
|
|
|
# 出现异常,打印异常 重新登陆
|
|
# 出现异常,打印异常 重新登陆
|
|
|
print(e)
|
|
print(e)
|
|
|
- flushCookie();
|
|
|
|
|
|
|
+ flushCookie()
|
|
|
|
|
|
|
|
|
|
|
|
|
def getData():
|
|
def getData():
|
|
|
- url = 'https://www.freewhale.co/user' # 将此链接替换为您要抓取的实际链接
|
|
|
|
|
|
|
+ url = '' # 将此链接替换为您要抓取的实际链接
|
|
|
global cookies
|
|
global cookies
|
|
|
try:
|
|
try:
|
|
|
response = requests.get(url, cookies=cookies, verify=False)
|
|
response = requests.get(url, cookies=cookies, verify=False)
|
|
@@ -67,6 +66,7 @@ def getData():
|
|
|
print(e)
|
|
print(e)
|
|
|
getData();
|
|
getData();
|
|
|
else:
|
|
else:
|
|
|
|
|
+ # 分析网页 获取数据
|
|
|
html = response.content
|
|
html = response.content
|
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
|
|
|
|