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
8f954c79
Commit
8f954c79
authored
Jun 18, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix samples
parent
312e1bce
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
37 deletions
+15
-37
README.md
README.md
+2
-2
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+1
-5
FreemarkerPipeline.java
...va/us/codecraft/webmagic/pipeline/FreemarkerPipeline.java
+1
-1
FreemarkerPipelineTest.java
...st/java/us/codecraft/webmagic/FreemarkerPipelineTest.java
+1
-1
wordpress.ftl
webmagic-plugin/src/test/resources/ftl/wordpress.ftl
+0
-23
DianpingProcessor.java
...java/us/codecraft/webmagic/samples/DianpingProcessor.java
+10
-5
No files found.
README.md
View file @
8f954c79
...
...
@@ -90,8 +90,8 @@ webmagic遵循[Apache 2.0协议](http://opensource.org/licenses/Apache-2.0)
webmagic的架构和设计参考了以下两个项目,感谢以下两个项目的作者:
python爬虫
**scrapy**
[
https://github.com/scrapy/scrapy
](
https://github.com/scrapy/scrapy
)
python爬虫
**scrapy**
[
https://github.com/scrapy/scrapy
](
https://github.com/scrapy/scrapy
)
Java爬虫
**Spiderman**
[
https://gitcafe.com/laiweiwei/Spiderman
](
https://gitcafe.com/laiweiwei/Spiderman
)
Java爬虫
**Spiderman**
[
https://gitcafe.com/laiweiwei/Spiderman
](
https://gitcafe.com/laiweiwei/Spiderman
)
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
8f954c79
...
...
@@ -57,10 +57,6 @@ public class Spider implements Runnable, Task {
return
this
;
}
public
Thread
thread
()
{
return
new
Thread
(
this
);
}
public
Spider
schedular
(
Schedular
schedular
)
{
this
.
schedular
=
schedular
;
return
this
;
...
...
@@ -74,7 +70,7 @@ public class Spider implements Runnable, Task {
@Override
public
void
run
()
{
for
(
String
startUrl
:
pageProcessor
.
getSite
().
getStartUrls
()
)
{
for
(
String
startUrl
:
startUrls
)
{
schedular
.
push
(
new
Request
(
startUrl
),
this
);
}
Request
request
=
schedular
.
poll
(
this
);
...
...
webmagic-plugin/src/main/java/us/codecraft/webmagic/pipeline/FreemarkerPipeline.java
View file @
8f954c79
...
...
@@ -30,7 +30,7 @@ public class FreemarkerPipeline implements Pipeline {
configuration
.
setDirectoryForTemplateLoading
(
new
File
(
this
.
getClass
().
getClassLoader
().
getResource
(
"ftl/"
).
getFile
()));
this
.
template
=
configuration
.
getTemplate
(
template
);
this
.
path
=
path
;
File
file
=
new
File
(
path
);
new
File
(
path
);
}
public
FreemarkerPipeline
(
String
template
)
throws
IOException
{
...
...
webmagic-plugin/src/test/java/us/codecraft/webmagic/FreemarkerPipelineTest.java
View file @
8f954c79
...
...
@@ -13,7 +13,7 @@ import java.io.IOException;
public
class
FreemarkerPipelineTest
{
@Test
public
void
test
()
throws
IOException
{
public
void
test
TemplateLoad
()
throws
IOException
{
FreemarkerPipeline
freemarkerPipeline
=
new
FreemarkerPipeline
(
"wordpress.ftl"
);
}
}
webmagic-plugin/src/test/resources/ftl/wordpress.ftl
deleted
100644 → 0
View file @
312e1bce
<item>
<title>$it.Title</title>
<link>http://127.0.0.1/wordpress/?p=$it.Id</link>
<pubDate>${date}</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">http://127.0.0.1/wordpress/?p=$it.Id</guid>
<description></description>
<content:encoded><![CDATA[${text}]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<#--<wp:post_id>$it.Id</wp:post_id>-->
<wp:post_date>${date}</wp:post_date>
<wp:post_date_gmt>${date}</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>${title}</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
$tags
</item>
\ No newline at end of file
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/Dianping
Blog
Processor.java
→
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/DianpingProcessor.java
View file @
8f954c79
...
...
@@ -2,6 +2,7 @@ package us.codecraft.webmagic.samples;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.Page
;
import
us.codecraft.webmagic.Spider
;
import
us.codecraft.webmagic.processor.PageProcessor
;
import
java.util.List
;
...
...
@@ -11,15 +12,14 @@ import java.util.List;
* Date: 13-4-21
* Time: 下午8:08
*/
public
class
Dianping
Blog
Processor
implements
PageProcessor
{
public
class
DianpingProcessor
implements
PageProcessor
{
@Override
public
void
process
(
Page
page
)
{
//http://progressdaily.diandian.com/post/2013-01-24/40046867275
List
<
String
>
requests
=
page
.
getHtml
().
rs
(
"<a[^<>]*href=[\"']{1}(/shop/.*?)[\"']{1}"
).
toStrings
();
List
<
String
>
requests
=
page
.
getHtml
().
as
().
rs
(
".*shop.*"
).
toStrings
();
page
.
addTargetRequests
(
requests
);
requests
=
page
.
getHtml
().
rs
(
"
<a[^<>]*href=[\"']{1}(/search/category/.*?)[\"']{1}
"
).
toStrings
();
requests
=
page
.
getHtml
().
rs
(
"
.*search/category/.*
"
).
toStrings
();
page
.
addTargetRequests
(
requests
);
if
(
page
.
getUrl
().
toString
().
contains
(
"shop"
)){
if
(
page
.
getUrl
().
toString
().
contains
(
"shop"
))
{
page
.
putField
(
"title"
,
page
.
getHtml
().
x
(
"//h1[@class='shop-title']"
));
page
.
putField
(
"content"
,
page
.
getHtml
().
sc
());
}
...
...
@@ -30,4 +30,9 @@ public class DianpingBlogProcessor implements PageProcessor {
return
Site
.
me
().
setDomain
(
"www.dianping.com"
).
addStartUrl
(
"http://www.dianping.com/"
).
setUserAgent
(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31"
);
}
public
static
void
main
(
String
[]
args
)
{
DianpingProcessor
dianpingProcessor
=
new
DianpingProcessor
();
Spider
.
me
().
processor
(
dianpingProcessor
).
startUrl
(
"http://www.dianping.com/shanghai/food"
).
run
();
}
}
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