webmagic ajax,webmagic 爬虫 分页

webmagic ajax,webmagic 爬虫 分页importus codecraft webmagic Page importus codecraft webmagic Site importus codecraft webmagic Spider importus codecraft webmagic processor PageProcesso importus codecraft webmagic selector JsonP

import us.codecraft.webmagic.Page;

import us.codecraft.webmagic.Site;

import us.codecraft.webmagic.Spider;

import us.codecraft.webmagic.processor.PageProcessor;

import us.codecraft.webmagic.selector.JsonPathSelector;

import us.codecraft.webmagic.selector.Selectors;

import java.util.List;

/

* @author 

* @since 0.5.0

*/

public class YidianzixunProcessor implements PageProcessor {

private Site site = Site.me();

// . ? 等特殊符号需要加\\引用符

private static final String ARTICLE_URL = “http://www\\.yidianzixun\\.com/home\\?page=article&id=\\w+”;

public void process(Page page) {

if (page.getUrl().regex(ARTICLE_URL).match()) {

String content = page.getHtml().xpath(“//div[@class=’content’]”).toString();

//1)文章头部:1、标题、2、发表时间、3、文章来源

String content_hd = Selectors.xpath(“//div[@class=’content-hd’]”).select(content);

String title = Selectors.xpath(“//h2/text()”).select(content_hd);

String date =  Selectors.xpath(“//div[@class=’meta’]/span[@class=’date’]/text()”).select(content_hd);

String source = Selectors.xpath(“//a[@id=’source-name’]/text()/text()”).select(content_hd);

//2)文章主题

String body = Selectors.xpath(“//div[@class=’content-bd’]”).select(content);

System.out.println(body);

} else {

List results = new JsonPathSelector(“$.result[*]”).selectList(page.getRawText());

for(String result:results){

// /home?page=article&id={
{docid}}&up={
{up}}#comment

// /home?page=article&id={
{docid}} 也是可以支持

String docid = new JsonPathSelector(“docid”).select(result);

String targetUrl = “http://www.yidianzixun.com/home?page=article&id=”+docid;

page.addTargetRequest(targetUrl);

}

}

}

public Site getSite() {

return site;

}

public static void main(String[] args) {

// url的特殊符号 ‘|’ : %7C

//通过ajax判断请求的参数

String targetUrl = “http://www.yidianzixun.com/api/q/?path=channel%7Cnews-list-for-keyword&display=%E8%8A%B1%E8%8C%B6&word_type=token&fields=docid&fields=category&fields=date&fields=image&fields=image_urls&fields=like&fields=source&fields=title&fields=url&fields=comment_count&fields=summary&fields=up&cstart=10&cend=20&version=&infinite=true”;

Spider.create(new YidianzixunProcessor()).addUrl(targetUrl).thread(5).run();

}

}

相关的包

us.codecraft

webmagic-core

0.5.3

us.codecraft

webmagic-extension

0.5.3

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233105.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • kalidirsearch_kali.org

    kalidirsearch_kali.orgdirsearch是一个python3开发的目录扫描工具,目的是扫描网站的敏感文件和目录从而找到突破口。dirsearch使用:-u指定网址-e指定网站语言-w指定字典-r递归目录(跑出目录后,继续跑目录下面的目录)-random-agents使用随机UApythondirsearch.py-u网址-e*模板:pythondirsearch.py-uhttp://5073135b-4e2c-4551-b64f-242d901d8076.chall

    2022年9月27日
    3
  • Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server)

    Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server)原文链接:http://www.sqlservercentral.com/articles/Stairway+Series/119429/BySolomonRutzky,2015/03/11TheSeriesThisarticleispartoftheStairwaySeries:StairwaytoSQLCLRThepossibil

    2022年7月20日
    12
  • host process for windows services已停止工作_diagnostic service host启动不了

    host process for windows services已停止工作_diagnostic service host启动不了解决WINXP系统开机后弹出Generichostprocessforwin32services遇到问题需要关闭!出现上面这个错误一般有三种情况。1.就是病毒。开机后会提示GenericHostProcessforWin32Services遇到问题需要关闭”“RemoteRrocedureCall(RPC)服务意外终止,然后就自…

    2022年10月12日
    4
  • Mac 长按键盘快速输入(长按输入慢的问题)

    Mac 长按键盘快速输入(长按输入慢的问题)

    2021年5月13日
    134
  • 池化层的作用[通俗易懂]

    maxpooling是CNN当中的最大值池化操作,其实用法和卷积很类似tf.nn.max_pool(value,ksize,strides,padding,name=None)参数是四个,和卷积很类似:第一个参数value:需要池化的输入,一般池化层接在卷积层后面,所以输入通常是featuremap,依然是[batch,height,width,channels]这样的shape第二个参数ksize:池化窗口的大小,取一个四维向量,一般是[1,height,width,1],

    2022年4月10日
    51
  • c语言中strstr函数怎么实现_c语言strstr函数怎么写

    c语言中strstr函数怎么实现_c语言strstr函数怎么写首先,我们来看strstr函数的使用可见,strstr函数是用来查找字串的一个函数。因为字符串中有“cde”子串,所以代码运行起来结果就是”cdef”。现在,我们已经将strstr函数的作用大概了解了一下,下面开始函数的模拟实现。首先,在cplusplus中搜索strstr可以了解到她返回的类型及参数相关链接:strstr-C++Reference(cplusplus.com)接下来,我们分析实现思路直到s1到了下图的位置,两者相等当*s1==*s2时进入while循环,s1+

    2022年10月9日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号