notes
notes copied to clipboard
使用Python抓取Shadowsocks账号
前奏
pip install requests
pip install beautifulsoup4
pip install lxml
pip install html5lib
fq.py
import requests
from bs4 import BeautifulSoup
import sys
import logging
reload(sys)
sys.setdefaultencoding('utf-8')
if sys.version_info[:3] < (2, 7, 9):
logging.captureWarnings(True)
r = requests.Session()
header = {
'Host':'www.ss-link.com',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
'Cookie':'yundunReferer=http%3A//blog.ss-link.com/archives/27; webpy_session_id=bc761f76d866de5d28e6317eba34996efc6bc2ac'
}
res = r.get('https://www.ss-link.com/my/free',headers = header)
soup = BeautifulSoup(res.text,'html.parser')
table = soup.find('tbody')
file = open('fq.txt','wb')
for row in table.findAll('tr'):
cells = row.findAll("td")
sevname = cells[0].find(text=True)
server = cells[1].find(text=True)
port = cells[2].find(text=True)
pwd = cells[3].find(text=True)
ser = cells[4].find(text=True)
file.write(sevname+"\t"+server+"\t"+port+"\t"+pwd+"\t"+ser+"\n")
file.close()
结果:
美国拉斯维加斯VW线路 76.164.197.155 9980 65310662 aes-256-cfb
美国拉斯维加斯VW线路 72.46.135.119 9980 65310662 aes-256-cfb
美国硅谷T2线路 173.252.220.201 9980 65310662 aes-256-cfb
美国洛杉矶GR线路 104.250.143.243 9980 65310662 aes-256-cfb
美国洛杉矶GR线路 104.250.146.37 9980 65310662 aes-256-cfb
美国洛杉矶GR线路 104.250.146.212 9980 65310662 aes-256-cfb
美国洛杉矶GR线路 104.250.144.10 9980 65310662 aes-256-cfb
美国洛杉矶GR线路 104.250.147.22 9980 65310662 aes-256-cfb
fq.py
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import re
import codecs
import sys
import logging
reload(sys)
sys.setdefaultencoding('utf-8')
# 设置日志级别
if sys.version_info[:3] < (2, 7, 9):
logging.captureWarnings(True)
# 获取数据
def getData():
r = requests.Session()
header = {
'Host':'www.ss-link.com',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
'Cookie':'yundunReferer=http%3A//blog.ss-link.com/archives/27; webpy_session_id=ef8d1722114f3934686f1b99d58874d4b30d10ee'
}
res = r.get('https://www.ss-link.com/my/free',headers = header)
soup = BeautifulSoup(res.text,'html.parser')
table = soup.find('tbody')
passwd = ''
for row in table.findAll('tr'):
cells = row.findAll("td")
pwd = cells[3].find(text=True)
passwd = pwd
return passwd
# 写文件
def writefile(passwd):
file = codecs.open('gui-config.json','w+','utf-8')
line = '''{
"configs" : [
{
"server" : "173.252.220.201",
"server_port" : 9980,
"password" : "21624209",
"method" : "aes-256-cfb",
"remarks" : "美国硅谷T2线路"}
,
{
"server" : "76.164.197.155",
"server_port" : 9980,
"password" : "21624209",
"method" : "aes-256-cfb",
"remarks" : "美国拉斯维加斯VW线路"}
,
{
"server" : "72.46.135.119",
"server_port" : 9980,
"password" : "21624209",
"method" : "aes-256-cfb",
"remarks" : "美国拉斯维加斯VW线路"}
],
"strategy" : null,
"index" : 0,
"global" : false,
"enabled" : false,
"shareOverLan" : false,
"isDefault" : false,
"localPort" : 1080,
"pacUrl" : null,
"useOnlinePac" : false}'''
str = re.sub('"password" : "\d+"','"password" : "'+passwd+'"',line)
file.write(str.decode('utf-8'))
file.close()
writefile(getData())
http://www.socks163.com
# -*- coding: utf-8 -*-
import requests
import lxml.html
import re
import codecs
import sys
import logging
reload(sys)
sys.setdefaultencoding('utf-8')
# 设置日志级别
if sys.version_info[:3] < (2, 7, 9):
logging.captureWarnings(True)
# 获取数据
def getData():
r = requests.Session()
header = {
'Host':'www.socks163.com',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36'
}
res = r.get('http://www.socks163.com/',headers = header)
content = res.text
doc = lxml.html.fromstring(content.decode("UTF-8"))
pwd = doc.xpath('//div[@class=\'row-fluid\'][1]/div[@class=\'span4\'][1]/p[3]/code')[0].text_content()
return pwd
# 写文件
def writefile(passwd):
file = codecs.open('gui-config.json','w+','utf-8')
line = '''{
"configs" : [
{
"server" : "104.128.233.13",
"server_port" : 443,
"password" : "m4aWT8GpJ5cs1ePY",
"method" : "aes-256-cfb",
"remarks" : "104.128.233.13"}
,
{
"server" : "104.128.233.14",
"server_port" : 443,
"password" : "m4aWT8GpJ5cs1ePY",
"method" : "aes-256-cfb",
"remarks" : "104.128.233.14"}
,
{
"server" : "104.128.233.15",
"server_port" : 443,
"password" : "m4aWT8GpJ5cs1ePY",
"method" : "aes-256-cfb",
"remarks" : "104.128.233.15"}
],
"strategy" : null,
"index" : 0,
"global" : false,
"enabled" : false,
"shareOverLan" : false,
"isDefault" : false,
"localPort" : 1080,
"pacUrl" : null,
"useOnlinePac" : false}'''
str = re.sub('"password" : "\w+"','"password" : "'+passwd+'"',line)
file.write(str.decode('utf-8'))
file.close()
writefile(getData())
http://www.ishadowsocks.com/
# -*- coding: utf-8 -*-
import requests
import lxml.html
import codecs
import sys
import logging
reload(sys)
sys.setdefaultencoding('utf-8')
# 设置日志级别
if sys.version_info[:3] < (2, 7, 9):
logging.captureWarnings(True)
# 获取数据
def getData():
r = requests.Session()
header = {
'Host':'www.ishadowsocks.com',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36'
}
res = r.get('http://www.ishadowsocks.com/',headers = header)
content = res.text
doc = lxml.html.fromstring(content.decode("UTF-8"))
pwdA = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][1]/h4[3]")[0].text_content()
pwdA = pwdA.decode('gbk').split(":")[1]
portA = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][1]/h4[2]")[0].text_content()
portA = portA.decode('gbk').split(":")[1]
pwdB = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][2]/h4[3]")[0].text_content()
pwdB = pwdB.decode('gbk').split(":")[1]
portB = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][2]/h4[2]")[0].text_content()
portB = portB.decode('gbk').split(":")[1]
pwdC = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][3]/h4[3]")[0].text_content()
pwdC = pwdC.decode('gbk').split(":")[1]
portC = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][3]/h4[2]")[0].text_content()
portC = portC.decode('gbk').split(":")[1]
file = codecs.open('gui-config.json','w+','utf-8')
line = '''{
"configs" : [
{
"server" : "US1.ISS.TF",
"server_port" : portA,
"password" : "pwdA",
"method" : "AES-256-CFB",
"remarks" : "US1.ISS.TF"}
,
{
"server" : "US2.ISS.TF",
"server_port" : portB,
"password" : "pwdB",
"method" : "AES-256-CFB",
"remarks" : "US2.ISS.TF"}
,
{
"server" : "JP3.ISS.TF",
"server_port" : portC,
"password" : "pwdC",
"method" : "AES-256-CFB",
"remarks" : "JP3.ISS.TF"}
],
"strategy" : null,
"index" : 0,
"global" : false,
"enabled" : false,
"shareOverLan" : false,
"isDefault" : false,
"localPort" : 1080,
"pacUrl" : null,
"useOnlinePac" : false}'''
str = line.replace('pwdA',pwdA).replace('pwdB',pwdB).replace('pwdC',pwdC).replace('portA',portA).replace('portB',portB).replace('portC',portC)
file.write(str.decode('utf-8'))
file.close()
getData()
http://www.ishadowsocks.org
# -*- coding: utf-8 -*-
import requests
import lxml.html
import codecs
import sys
import logging
reload(sys)
sys.setdefaultencoding('utf-8')
# 设置日志级别
if sys.version_info[:3] < (2, 7, 9):
logging.captureWarnings(True)
# 获取数据
def getData():
r = requests.Session()
header = {
'Host':'www.ishadowsocks.org',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36'
}
res = r.get('http://www.ishadowsocks.org/',headers = header)
content = res.text
doc = lxml.html.fromstring(content.decode("UTF-8"))
pwdA = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][1]/h4[3]")[0].text_content()
pwdA = pwdA.split(":")[1]
portA = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][1]/h4[2]")[0].text_content()
portA = portA.split(":")[1]
pwdB = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][2]/h4[3]")[0].text_content()
pwdB = pwdB.split(":")[1]
portB = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][2]/h4[2]")[0].text_content()
portB = portB.split(":")[1]
pwdC = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][3]/h4[3]")[0].text_content()
pwdC = pwdC.split(":")[1]
portC = doc.xpath("//body[@id='page-top']/section[@id='free']/div[@class='container']/div[@class='row'][2]/div[@class='col-lg-4 text-center'][3]/h4[2]")[0].text_content()
portC = portC.split(":")[1]
file = codecs.open('gui-config.json','w+','utf-8')
line = '''{
"auto_disconnect_connection" : false,
"autoban" : false,
"configs" : [
{
"ConnectedTimes" : 28274,
"Download_traffic" : 185566423.0,
"FailureTimes" : 17166,
"Latency" : 0,
"Speed" : 0,
"Upload_traffic" : 10297825.0,
"enable" : true,
"method" : "aes-256-cfb",
"password" : "pwdC",
"remarks" : "",
"server" : "JP3.ISS.TF",
"server_port" : portC
},
{
"ConnectedTimes" : 21,
"Download_traffic" : 19228.0,
"FailureTimes" : 1,
"Latency" : 171,
"Speed" : 80,
"Upload_traffic" : 15359.0,
"enable" : true,
"method" : "aes-256-cfb",
"password" : "pwdA",
"remarks" : "",
"server" : "US1.ISS.TF",
"server_port" : portA
},
{
"ConnectedTimes" : 1395,
"Download_traffic" : 15278189.0,
"FailureTimes" : 998,
"Latency" : 0,
"Speed" : 0,
"Upload_traffic" : 1172429.0,
"enable" : true,
"method" : "aes-256-cfb",
"password" : "pwdB",
"remarks" : "",
"server" : "HK2.ISS.TF",
"server_port" : portB
}
],
"enable" : true,
"global" : false,
"idInUse" : 0,
"index" : 0,
"localPort" : 1080,
"localSocksPass" : "",
"localSocksUser" : "",
"m_HotKeyForAddFromQRCode" : 0,
"pacUrl" : "",
"random" : false,
"reconnectTimes" : 3,
"runAtStartup" : false,
"shareOverLan" : false,
"startInSystray" : false,
"strHotKey" : "",
"testing_url" : "http://global.bing.com",
"useOnlinePac" : false
}
'''
str = line.replace('pwdA',pwdA).replace('pwdB',pwdB).replace('pwdC',pwdC).replace('portA',portA).replace('portB',portB).replace('portC',portC)
file.write(str.decode('utf-8'))
file.close()
getData()