forked from rbridomzmr/ShadowSocks-Share
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xxx <x@x.x>
- Loading branch information
xxx
committed
Jan 8, 2018
1 parent
7af28fb
commit 3e9ed19
Showing
5 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
import java.util.Set; | ||
|
||
/** | ||
* doub 爬虫 | ||
* doub | ||
* https://doub.io | ||
*/ | ||
@Slf4j | ||
|
91 changes: 91 additions & 0 deletions
91
src/main/java/com/example/ShadowSocksShare/service/impl/FreeSSRCrawlerServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.example.ShadowSocksShare.service.impl; | ||
|
||
import com.example.ShadowSocksShare.domain.ShadowSocksDetailsEntity; | ||
import com.example.ShadowSocksShare.service.ShadowSocksCrawlerService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.math.NumberUtils; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* 免费shadowsocks账号 | ||
* https://freessr.win/ | ||
*/ | ||
@Slf4j | ||
@Service | ||
public class FreeSSRCrawlerServiceImpl extends ShadowSocksCrawlerService { | ||
// 目标网站 URL | ||
private static final String TARGET_URL = "https://freessr.win/"; | ||
|
||
/** | ||
* 网页内容解析 ss 信息 | ||
*/ | ||
@Override | ||
protected Set<ShadowSocksDetailsEntity> parse(Document document) { | ||
Elements ssList = document.select("div.text-center"); | ||
|
||
Set<ShadowSocksDetailsEntity> set = new HashSet(ssList.size()); | ||
for (int i = 0; i < ssList.size(); i++) { | ||
try { | ||
Element element = ssList.get(i); | ||
// 取 h4 信息,为 ss 信息 | ||
Elements ssHtml = element.select("h4"); | ||
|
||
if (ssHtml.size() >= 5) { | ||
// server | ||
String server = StringUtils.remove(ssHtml.get(0).text(), "服务器地址:"); | ||
Assert.hasLength(server, "server 不能为空"); | ||
|
||
int server_port = NumberUtils.toInt(StringUtils.remove(ssHtml.get(1).text(), "端口:")); | ||
// Assert.isNull(port, "port 不能为空"); | ||
|
||
|
||
String password = StringUtils.remove(ssHtml.get(2).text(), "密码:"); | ||
Assert.hasLength(password, "password 不能为空"); | ||
|
||
String method = StringUtils.remove(ssHtml.get(3).text(), "加密方式:"); | ||
Assert.hasLength(method, "method 不能为空"); | ||
|
||
// 账号状态 | ||
String status = ssHtml.get(4).text(); | ||
if (status.contains("正常")) { | ||
ShadowSocksDetailsEntity ss = new ShadowSocksDetailsEntity(server, server_port, password, method, SS_PROTOCOL, SS_OBFS); | ||
ss.setValid(false); | ||
ss.setValidTime(new Date()); | ||
ss.setRemarks(TARGET_URL); | ||
ss.setGroup("ShadowSocks-Share"); | ||
|
||
// 测试网络 | ||
if (isReachable(ss)) | ||
ss.setValid(true); | ||
|
||
// 无论是否可用都入库 | ||
set.add(ss); | ||
|
||
log.debug("*************** 第 {} 条 ***************{}{}", i + 1, System.lineSeparator(), ss); | ||
// log.debug("{}", ss.getLink()); | ||
} | ||
} | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
} | ||
return set; | ||
} | ||
|
||
/** | ||
* 目标网站 URL | ||
*/ | ||
@Override | ||
protected String getTargetURL() { | ||
return TARGET_URL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters