All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.codecraft.webmagic.example.GithubRepoApi Maven / Gradle / Ivy

The newest version!
package us.codecraft.webmagic.example;

import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.model.ConsolePageModelPipeline;
import us.codecraft.webmagic.model.HasKey;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.ExtractByUrl;

import java.util.List;

/**
 * @author [email protected] 
* @since 0.4.1 */ public class GithubRepoApi implements HasKey { @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name", source = ExtractBy.Source.RawText) private String name; @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..owner.login", source = ExtractBy.Source.RawText) private String author; @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.language",multi = true, source = ExtractBy.Source.RawText) private List language; @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.stargazers_count", source = ExtractBy.Source.RawText) private int star; @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.forks_count", source = ExtractBy.Source.RawText) private int fork; @ExtractByUrl private String url; public static void main(String[] args) { OOSpider.create(Site.me().setSleepTime(100) , new ConsolePageModelPipeline(), GithubRepoApi.class) .addUrl("https://api.github.com/repos/code4craft/webmagic").run(); } @Override public String key() { return author + ":" + name; } public String getName() { return name; } public String getAuthor() { return author; } public List getLanguage() { return language; } public String getUrl() { return url; } public int getStar() { return star; } public int getFork() { return fork; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy