Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenweiyang
wechat
Commits
3def1c02
Commit
3def1c02
authored
Jul 30, 2020
by
shenjunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加Response close
parent
0348e2a1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
26 deletions
+45
-26
pom.xml
+1
-1
src/main/java/com/zhiwei/wechat/search/WechatReal.java
+44
-25
No files found.
pom.xml
View file @
3def1c02
...
...
@@ -3,7 +3,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.zhiwei
</groupId>
<artifactId>
wechat
</artifactId>
<version>
1.3.
4
-SNAPSHOT
</version>
<version>
1.3.
6
-SNAPSHOT
</version>
<description>
知微微信采集程序,包含
1.微信历史文章采集
...
...
src/main/java/com/zhiwei/wechat/search/WechatReal.java
View file @
3def1c02
...
...
@@ -61,29 +61,48 @@ public class WechatReal {
}
headers
.
put
(
"cookie"
,
cookie
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
htmlBody
=
httpBoot
.
syncCall
(
RequestUtils
.
wrapGet
(
url
,
headers
),
proxy
).
body
().
string
();
if
(
StringUtils
.
isNotBlank
(
htmlBody
)
&&
!
htmlBody
.
contains
(
"验证码"
))
{
Response
response
=
null
;
try
{
response
=
httpBoot
.
syncCall
(
RequestUtils
.
wrapGet
(
url
,
headers
),
proxy
);
String
htmlBody
=
response
.
body
().
string
();
// cookie过期
if
(
StringUtils
.
isNotBlank
(
htmlBody
)
||
htmlBody
.
contains
(
"验证码"
))
{
initCookie
(
url
,
headers
,
proxy
);
continue
;
}
StringBuilder
furl
=
new
StringBuilder
();
Matcher
ma1
=
PATTERN
.
matcher
(
htmlBody
);
while
(
ma1
.
find
())
{
furl
.
append
(
ma1
.
group
(
1
));
}
return
furl
.
toString
();
}
else
{
// cookie过期
initCookie
(
url
,
headers
,
proxy
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
}
finally
{
if
(
null
!=
response
)
{
response
.
close
();
}
}
}
throw
new
NullPointerException
(
"ip:"
+
proxy
.
address
()
+
"获取临时链接失败, 出现输入验证码"
);
}
private
void
initCookie
(
String
url
,
Map
<
String
,
Object
>
headers
,
Proxy
proxy
)
throws
IOException
{
private
void
initCookie
(
String
url
,
Map
<
String
,
Object
>
headers
,
Proxy
proxy
)
{
Response
response
=
null
;
try
{
Request
request
=
RequestUtils
.
wrapGet
(
getSearchUrl
(
url
),
headers
);
Response
response
=
httpBoot
.
syncCall
(
request
,
proxy
);
response
=
httpBoot
.
syncCall
(
request
,
proxy
);
// System.out.println("htmlBody:" + response.body().string());
cookie
=
response
.
headers
(
"set-cookie"
).
stream
().
map
(
s
->
s
.
replaceAll
(
";.*"
,
""
))
.
collect
(
Collectors
.
joining
(
"; "
));
logger
.
info
(
"ip:{},初始化cookie:{}"
,
proxy
.
address
(),
cookie
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"ip:{},初始化cookie异常:"
,
proxy
.
address
(),
e
);
}
finally
{
if
(
null
!=
response
)
{
response
.
close
();
}
}
}
/**
...
...
@@ -101,24 +120,24 @@ public class WechatReal {
timestamp
,
"&lkt=1%2C"
,
timestamp
,
"%2C"
,
timestamp
);
}
/**
* 获取转链接的中间跳转链接
*
* @param originalUrl
* @return
*/
@Deprecated
private
static
String
getOriginalUrl
(
String
originalUrl
)
{
int
b
=
(
int
)
(
Math
.
floor
(
100
*
Math
.
random
())
+
1
);
int
a
=
originalUrl
.
indexOf
(
"url="
);
int
c
=
originalUrl
.
indexOf
(
"&k="
);
String
d
=
null
;
if
(
a
!=
-
1
&&
-
1
==
c
)
{
d
=
originalUrl
.
substring
(
a
+
25
+
b
,
a
+
26
+
b
);
}
originalUrl
+=
"&k="
+
b
+
"&h="
+
d
;
return
originalUrl
;
}
//
/**
//
* 获取转链接的中间跳转链接
//
*
//
* @param originalUrl
//
* @return
//
*/
//
@Deprecated
//
private static String getOriginalUrl(String originalUrl) {
//
int b = (int) (Math.floor(100 * Math.random()) + 1);
//
int a = originalUrl.indexOf("url=");
//
int c = originalUrl.indexOf("&k=");
//
String d = null;
//
if (a != -1 && -1 == c) {
//
d = originalUrl.substring(a + 25 + b, a + 26 + b);
//
}
//
originalUrl += "&k=" + b + "&h=" + d;
//
return originalUrl;
//
}
// public static void main(String[] args) throws Exception {
// WechatReal real = new WechatReal();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment