项目作者: fcannizzaro

项目描述 :
Jsoup Annotations POJO
高级语言: Java
项目地址: git://github.com/fcannizzaro/jsoup-annotations.git
创建时间: 2017-05-07T15:17:18Z
项目社区:https://github.com/fcannizzaro/jsoup-annotations

开源协议:Apache License 2.0

下载


jsoup-annotations

Jsoup Annotations POJO


Build Status
Android Arsenal
Codacy Badge

Gradle Dependency

Step 1.

Add the JitPack repository to your build file

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Step 2.

Add the dependency

  1. dependencies {
  2. compile 'com.github.fcannizzaro:jsoup-annotations:1.0.3'
  3. }

Usage

  1. Element html = Jsoup.connect("https://www.npmjs.com/").get();
  2. /*
  3. * Scrape!
  4. * Use JsoupProcessor or JP
  5. */
  6. NPM npm = JP.from(html, NPM.class);
  7. // or
  8. List<Package> packages = JP.fromList(html, Package.class);

See Sample Code

Annotations

@Selector(String: query)

Can be used for class or field.

  1. @Selector("#content")
  2. class Content {
  3. // internal elements
  4. }

@Text(String: query)

  1. @Text("h3")
  2. String title;

@Html(String: query)

  1. @Html("div.inner")
  2. String html;

@Attr(String: query, String: attr)

  1. @Attr(query="a", attr="href")
  2. String href;

Text, Html, Attr can be also attached to methods like:

  1. @Text("head > title")
  2. void title(String title){
  3. // do something with result
  4. }

@ForEach(String: query)

  1. @ForEach("li")
  2. void iterate(Element element, int index){
  3. // [required] element
  4. // [optional] index
  5. // do something
  6. }

@AfterBind

  1. @AfterBind
  2. void attached(){
  3. // called after object binding is completed.
  4. }

@Child

Denote Field as child element (POJO).

@Items

Denote Field as List of Elements (POJO).

Author

Francesco Cannizzaro (fcannizzaro)

License

  1. Copyright 2017 Francesco Saverio Cannizzaro
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.