Skip to content

Commit

Permalink
new case
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkook committed Oct 9, 2021
1 parent 1dc97b3 commit 181fbf4
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 81 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# easyhtml
# About

自动提取HTML的文章列表和文章正文
无需输入任何标签信息及正则信息
支持大部分主流博客和新闻站点

## 安装
## Install

```shell
# tmkook/easyhtml 1.0
composer require "tmkook/easyhtml:*"
composer require "tmkook/easyhtml:1.0"
```

## 使用
## How to use

```php
//$data可以是URL或HTML
$easy = new Tmkook\EasyHTML($data);

//或者
$easy = new Tmkook\EasyHTML;
$easy->loadURL('http url'); //加载一个URL
$easy->loadURL('https://example.com/news'); //加载一个URL
$easy->loadHTML($html); //或者加载一段HTML


//获取当前页面所有文章链接和分页链接
//return ['list'=>list,'page'=>page]
//return ['list'=>$list,'title'=>$title,'page'=>$page]
$easy->getList();

//获取当前页面文章内容,相对链接转换可使用 EasyContent
Expand Down Expand Up @@ -57,7 +57,7 @@ https://www.php.net/manual/en/class.domdocument.php

```

## EasyContent 相对链接转换
## Relative link to absolute link

```php
//相对链接转换绝对链接的域名
Expand All @@ -70,7 +70,8 @@ $content = $easy->getContent();
$easyContent = new Tmkook\EasyContent($url,$content);

//或者
$easyContent = new Tmkook\EasyContent($url);
$easyContent = new Tmkook\EasyContent;
$easyContent->setBase($url);
$easyContent->setContent($content);

//获取转换后的正文
Expand All @@ -84,6 +85,11 @@ $easyContent->getImages($length);//获取多少个正文图片,默认为0取

```

## case

https://www.kmola.com


## License

MIT
1 change: 0 additions & 1 deletion example.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
print_r($easy->getMeta("description"));

$main = new Tmkook\EasyContent('http://example.com',$easy->getContent());
$main->fixUrl();

print_r($main->getText());
print_r($main->getContent());
Expand Down
2 changes: 2 additions & 0 deletions src/EasyContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function url($link){
if(empty($info['host'])){
$info['scheme'] = $site['scheme'];
$info['host'] = $site['host'];
}else if(empty($info['scheme'])){
$info['scheme'] = $site['scheme'];
}
$rel = empty($site['path'])? '/' : $site['path'];
$path = empty($info['path'])? '/' : $info['path'];
Expand Down
Loading

0 comments on commit 181fbf4

Please sign in to comment.