Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
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
沈俊林
webmagic
Commits
d07941d9
Commit
d07941d9
authored
Jun 03, 2017
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SimpleHttpClientTest
parent
592fa2c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
SimpleHttpClientTest.java
...test/java/us/codecraft/webmagic/SimpleHttpClientTest.java
+87
-0
No files found.
webmagic-extension/src/test/java/us/codecraft/webmagic/SimpleHttpClientTest.java
0 → 100644
View file @
d07941d9
package
us
.
codecraft
.
webmagic
;
import
org.junit.Test
;
import
us.codecraft.webmagic.model.AfterExtractor
;
import
us.codecraft.webmagic.model.annotation.ExtractBy
;
/**
* @author code4crafter@gmail.com
* Date: 2017/6/3
* Time: 下午2:54
*/
public
class
SimpleHttpClientTest
{
public
static
class
Weather
implements
AfterExtractor
{
private
String
location
;
@ExtractBy
(
notNull
=
true
,
value
=
"//div[@id='7d']//ul[@class='t']/li[2]/p[@class='tem']/i/regex('([\\-\\d]+)',1)"
)
private
Integer
lowTemperature
;
@ExtractBy
(
notNull
=
true
,
value
=
"//div[@id='7d']//ul[@class='t']/li[2]/p[@class='tem']/span/regex('([\\-\\d]+)',1)"
)
private
Integer
highTemperature
;
@ExtractBy
(
notNull
=
true
,
value
=
"//div[@id='7d']//ul[@class='t']/li[2]/p[@class='wea']/text()"
)
private
String
desc
;
@Override
public
void
afterProcess
(
Page
page
)
{
if
(
lowTemperature
>
highTemperature
)
{
int
temp
=
lowTemperature
;
lowTemperature
=
highTemperature
;
highTemperature
=
temp
;
}
}
public
String
getLocation
()
{
return
location
;
}
public
void
setLocation
(
String
location
)
{
this
.
location
=
location
;
}
public
Integer
getLowTemperature
()
{
return
lowTemperature
;
}
public
void
setLowTemperature
(
Integer
lowTemperature
)
{
this
.
lowTemperature
=
lowTemperature
;
}
public
Integer
getHighTemperature
()
{
return
highTemperature
;
}
public
void
setHighTemperature
(
Integer
highTemperature
)
{
this
.
highTemperature
=
highTemperature
;
}
public
String
getDesc
()
{
return
desc
;
}
public
void
setDesc
(
String
desc
)
{
this
.
desc
=
desc
;
}
@Override
public
String
toString
()
{
return
"Weather{"
+
"location='"
+
location
+
'\''
+
", lowTemperature="
+
lowTemperature
+
", highTemperature="
+
highTemperature
+
", desc='"
+
desc
+
'\''
+
'}'
;
}
}
@Test
public
void
test
()
throws
Exception
{
SimpleHttpClient
simpleClient
=
new
SimpleHttpClient
(
Site
.
me
().
setUserAgent
(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36"
));
Weather
weather
=
simpleClient
.
get
(
"http://www.weather.com.cn/weather/101020100.shtml"
,
Weather
.
class
);
System
.
out
.
println
(
weather
);
}
}
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