Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
feat: add pattern & patternMore options (#38)
Browse files Browse the repository at this point in the history
* feat: add pattern & patternMore options

* docs: Update README and add code list"

* fix(folder): `docs` -> `code-list`

* fix: typo

* docs: update code-list
  • Loading branch information
neighborhood999 authored Jul 23, 2018
1 parent b62b245 commit 4423b9e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 72 deletions.
98 changes: 43 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Easy scraping [591](https://rent.591.com.tw/) rent information.

## Requirement

```sh
```shell
$ go get -u github.com/vinta/pangu
$ go get -u github.com/PuerkitoBio/goquery
$ go get -u github.com/google/go-querystring/query
```

## Installation

```sh
```shell
$ go get github.com/neighborhood999/fiveN1-rent-scraper
```

Expand All @@ -33,8 +33,8 @@ import (
)

func main() {
o := rent.NewOptions()
url, err := rent.GenerateURL(o)
options := rent.NewOptions()
url, err := rent.GenerateURL(options)
if err != nil {
log.Fatalf("\x1b[91;1m%s\x1b[0m", err)
}
Expand Down Expand Up @@ -78,79 +78,67 @@ Index number is the representation **page number**, every index contain **30** i
Create and generate URL by options:

```go
o := rent.NewOptions()
url, err := rent.GenerateURL(o)
options := rent.NewOptions()
url, err := rent.GenerateURL(options)
if err != nil {
log.Fatal(err)
}

log.Println(url)
```

You may set more options for your requirement. Reference below `Options` struct comment:
You may set more options for your requirement. Reference below `Options` struct:

```go
type Options struct {
Region int `url:"region"` // 地區 - 預設:`1`
Section string `url:"section,omitempty"` // 鄉鎮 - 可選擇多個區域,例如:`section=7,4`
Kind int `url:"kind"` // 租屋類型 - `0`:不限、`1`:整層住家、`2`:獨立套房、`3`:分租套房、`4`:雅房、`8`:車位,`24`:其他
RentPrice string `url:"rentprice,omitempty"` // 租金 - `2`:5k - 10k、`3`:10k - 20k、`4`: 20k - 30k;或者可以輸入價格範圍,例如:`0,10000`
Area string `url:"area,omitempty"` // 坪數格式 - `10,20`(10 到 20 坪)
Order string `url:"order"` // 貼文時間 - 預設使用刊登時間:`posttime`,或是使用價格排序:`money`
OrderType string `url:"orderType"` // 排序方式 - `desc` 或 `asc`
Sex int `url:"sex,omitempty"` // 性別 - `0`:不限、`1`:男性、`2`:女性
HasImg string `url:"hasimg,omitempty"` // 過濾是否有「房屋照片」 - ``:空值(不限)、`1`:是
NotCover string `url:"not_cover,omitempty"` // 過濾是否為「頂樓加蓋」 - ``:空值(不限)、`1`:是
Role string `url:"role,omitempty"` // 過濾是否為「屋主刊登」 - ``:空值(不限)、`1`:是
Shape string `url:"shape,omitempty"` // 房屋類型 - `1`:公寓、`2`:電梯大樓、`3`:透天厝、`4`:別墅
Floor string `url:"floor,omitempty"` // 樓層 - `0,0`:不限、`0,1`:一樓、`2,6`:二樓到六樓、`6,12`:六樓到十二樓、`12,`:十二樓以上
Option string `url:"option,omitempty"` // 提供設備 - `tv`:電視、`cold`:冷氣、`icebox`:冰箱、`hotwater`:熱水器、`naturalgas`:天然瓦斯、`four`:第四台、`broadband`:網路、`washer`:洗衣機、`bed`:床、`wardrobe`:衣櫃、`sofa`:沙發。可選擇多個設備,例如:option=tv,cold
Other string `url:"other,omitempty"` // 其他條件 - `cartplace`:有車位、`lift`:有電梯、`balcony_1`:有陽台、`cook`:可開伙、`pet`:可養寵物、`tragoods`:近捷運、`lease`:可短期租賃。可選擇多個條件,例如:other=cartplace,cook
FirstRow int `url:"firstRow"`
Region int `url:"region"` // 地區 - 預設:`1`
Section string `url:"section,omitempty"` // 鄉鎮 - 可選擇多個區域,例如:`section=7,4`
Kind int `url:"kind"` // 租屋類型 - `0`:不限、`1`:整層住家、`2`:獨立套房、`3`:分租套房、`4`:雅房、`8`:車位,`24`:其他
RentPrice string `url:"rentprice,omitempty"` // 租金 - `2`:5k - 10k、`3`:10k - 20k、`4`: 20k - 30k;或者可以輸入價格範圍,例如:`0,10000`
Area string `url:"area,omitempty"` // 坪數格式 - `10,20`(10 到 20 坪)
Order string `url:"order"` // 貼文時間 - 預設使用刊登時間:`posttime`,或是使用價格排序:`money`
OrderType string `url:"orderType"` // 排序方式 - `desc` 或 `asc`
Sex int `url:"sex,omitempty"` // 性別 - `0`:不限、`1`:男性、`2`:女性
HasImg string `url:"hasimg,omitempty"` // 過濾是否有「房屋照片」 - ``:空值(不限)、`1`:是
NotCover string `url:"not_cover,omitempty"` // 過濾是否為「頂樓加蓋」 - ``:空值(不限)、`1`:是
Role string `url:"role,omitempty"` // 過濾是否為「屋主刊登」 - ``:空值(不限)、`1`:是
Shape string `url:"shape,omitempty"` // 房屋類型 - `1`:公寓、`2`:電梯大樓、`3`:透天厝、`4`:別墅
Pattern string `url:"pattern,omitempty"` // 格局單選 - `0`:不限、`1`:一房、`2``:兩房、`3`:三房、`4`:四房、`5`:五房以上
PatternMore string `url:"patternMore,omitempty"` // 格局多選 - 參考「格局單選」,可以選多種格局,例如:`1,2,3,4,5`
Floor string `url:"floor,omitempty"` // 樓層 - `0,0`:不限、`0,1`:一樓、`2,6`:二樓到六樓、`6,12`:六樓到十二樓、`12,`:十二樓以上
Option string `url:"option,omitempty"` // 提供設備 - `tv`:電視、`cold`:冷氣、`icebox`:冰箱、`hotwater`:熱水器、`naturalgas`:天然瓦斯、`four`:第四台、`broadband`:網路、`washer`:洗衣機、`bed`:床、`wardrobe`:衣櫃、`sofa`:沙發。可選擇多個設備,例如:option=tv,cold
Other string `url:"other,omitempty"` // 其他條件 - `cartplace`:有車位、`lift`:有電梯、`balcony_1`:有陽台、`cook`:可開伙、`pet`:可養寵物、`tragoods`:近捷運、`lease`:可短期租賃。可選擇多個條件,例如:other=cartplace,cook
FirstRow int `url:"firstRow"`
}
```

## Multiple Page Scrape
For example:

```go
options := rent.NewOptions()
options.Kind = 3
options.HasImg = "1"
options.NotCover = "1"
options.Role = "1"

rent.GenerateURL(options)
```

## Multiple Page

If you want to get more rent pieces of information, setting page amount in `Scrape` method:

```go
f := rent.NewFiveN1(url)
f.Scrape(5) // Page 1-5
f.Scrape(5) // page.1 to page.5
```

When amount `> 1`, it will start goroutine automatically and correspond to the page number to scrape.

## `urlJumpIp` Code List

| Area | Code |
| :----- | :--- |
| 台北市 | 1 |
| 基隆市 | 2 |
| 新北市 | 3 |
| 新竹市 | 4 |
| 新竹縣 | 5 |
| 桃園市 | 6 |
| 苗栗縣 | 7 |
| 台中市 | 8 |
| 彰化縣 | 10 |
| 南投縣 | 11 |
| 嘉義市 | 12 |
| 嘉義縣 | 13 |
| 雲林縣 | 14 |
| 台南市 | 15 |
| 高雄市 | 17 |
| 屏東縣 | 19 |
| 宜蘭縣 | 21 |
| 台東縣 | 22 |
| 花蓮縣 | 23 |
| 澎湖縣 | 24 |
| 金門縣 | 25 |
| 連江縣 | 26 |

## Secion Code List

More section code list reference to: [Section Code List](./docs/section-code-list.md).
## Code List

- [URL Jump ID Code List(地區列表)](./code-list/url-jump-ip-code-list.md)
- [Secion Code List(鄉鎮列表)](./code-list/section-code-list.md)

## LICENSE

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 各縣市鄉鎮地區代號
## `section` Code List(各縣市鄉鎮地區代號

<h3>台北市</h3>
<table>
Expand Down
26 changes: 26 additions & 0 deletions code-list/url-jump-ip-code-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## `urlJumpIp` Code List(各縣市地區代號)

| Area | Code |
| :----- | :--- |
| 台北市 | 1 |
| 基隆市 | 2 |
| 新北市 | 3 |
| 新竹市 | 4 |
| 新竹縣 | 5 |
| 桃園市 | 6 |
| 苗栗縣 | 7 |
| 台中市 | 8 |
| 彰化縣 | 10 |
| 南投縣 | 11 |
| 嘉義市 | 12 |
| 嘉義縣 | 13 |
| 雲林縣 | 14 |
| 台南市 | 15 |
| 高雄市 | 17 |
| 屏東縣 | 19 |
| 宜蘭縣 | 21 |
| 台東縣 | 22 |
| 花蓮縣 | 23 |
| 澎湖縣 | 24 |
| 金門縣 | 25 |
| 連江縣 | 26 |
34 changes: 18 additions & 16 deletions rent.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ type HouseInfo struct {

// Options is the representation query argument.
type Options struct {
Region int `url:"region"` // 地區 - 預設:`1`
Section string `url:"section,omitempty"` // 鄉鎮 - 可選擇多個區域,例如:`section=7,4`
Kind int `url:"kind"` // 租屋類型 - `0`:不限、`1`:整層住家、`2`:獨立套房、`3`:分租套房、`4`:雅房、`8`:車位,`24`:其他
RentPrice string `url:"rentprice,omitempty"` // 租金 - `2`:5k - 10k、`3`:10k - 20k、`4`: 20k - 30k;或者可以輸入價格範圍,例如:`0,10000`
Area string `url:"area,omitempty"` // 坪數格式 - `10,20`(10 到 20 坪)
Order string `url:"order"` // 貼文時間 - 預設使用刊登時間:`posttime`,或是使用價格排序:`money`
OrderType string `url:"orderType"` // 排序方式 - `desc` 或 `asc`
Sex int `url:"sex,omitempty"` // 性別 - `0`:不限、`1`:男性、`2`:女性
HasImg string `url:"hasimg,omitempty"` // 過濾是否有「房屋照片」 - ``:空值(不限)、`1`:是
NotCover string `url:"not_cover,omitempty"` // 過濾是否為「頂樓加蓋」 - ``:空值(不限)、`1`:是
Role string `url:"role,omitempty"` // 過濾是否為「屋主刊登」 - ``:空值(不限)、`1`:是
Shape string `url:"shape,omitempty"` // 房屋類型 - `1`:公寓、`2`:電梯大樓、`3`:透天厝、`4`:別墅
Floor string `url:"floor,omitempty"` // 樓層 - `0,0`:不限、`0,1`:一樓、`2,6`:二樓到六樓、`6,12`:六樓到十二樓、`12,`:十二樓以上
Option string `url:"option,omitempty"` // 提供設備 - `tv`:電視、`cold`:冷氣、`icebox`:冰箱、`hotwater`:熱水器、`naturalgas`:天然瓦斯、`four`:第四台、`broadband`:網路、`washer`:洗衣機、`bed`:床、`wardrobe`:衣櫃、`sofa`:沙發。可選擇多個設備,例如:option=tv,cold
Other string `url:"other,omitempty"` // 其他條件 - `cartplace`:有車位、`lift`:有電梯、`balcony_1`:有陽台、`cook`:可開伙、`pet`:可養寵物、`tragoods`:近捷運、`lease`:可短期租賃。可選擇多個條件,例如:other=cartplace,cook
FirstRow int `url:"firstRow"`
Region int `url:"region"` // 地區 - 預設:`1`
Section string `url:"section,omitempty"` // 鄉鎮 - 可選擇多個區域,例如:`section=7,4`
Kind int `url:"kind"` // 租屋類型 - `0`:不限、`1`:整層住家、`2`:獨立套房、`3`:分租套房、`4`:雅房、`8`:車位,`24`:其他
RentPrice string `url:"rentprice,omitempty"` // 租金 - `2`:5k - 10k、`3`:10k - 20k、`4`: 20k - 30k;或者可以輸入價格範圍,例如:`0,10000`
Area string `url:"area,omitempty"` // 坪數格式 - `10,20`(10 到 20 坪)
Order string `url:"order"` // 貼文時間 - 預設使用刊登時間:`posttime`,或是使用價格排序:`money`
OrderType string `url:"orderType"` // 排序方式 - `desc` 或 `asc`
Sex int `url:"sex,omitempty"` // 性別 - `0`:不限、`1`:男性、`2`:女性
HasImg string `url:"hasimg,omitempty"` // 過濾是否有「房屋照片」 - ``:空值(不限)、`1`:是
NotCover string `url:"not_cover,omitempty"` // 過濾是否為「頂樓加蓋」 - ``:空值(不限)、`1`:是
Role string `url:"role,omitempty"` // 過濾是否為「屋主刊登」 - ``:空值(不限)、`1`:是
Shape string `url:"shape,omitempty"` // 房屋類型 - `1`:公寓、`2`:電梯大樓、`3`:透天厝、`4`:別墅
Pattern string `url:"pattern,omitempty"` // 格局單選 - `0`:不限、`1`:一房、`2``:兩房、`3`:三房、`4`:四房、`5`:五房以上
PatternMore string `url:"patternMore,omitempty"` // 格局多選 - 參考「格局單選」,可以選多種格局,例如:`1,2,3,4,5`
Floor string `url:"floor,omitempty"` // 樓層 - `0,0`:不限、`0,1`:一樓、`2,6`:二樓到六樓、`6,12`:六樓到十二樓、`12,`:十二樓以上
Option string `url:"option,omitempty"` // 提供設備 - `tv`:電視、`cold`:冷氣、`icebox`:冰箱、`hotwater`:熱水器、`naturalgas`:天然瓦斯、`four`:第四台、`broadband`:網路、`washer`:洗衣機、`bed`:床、`wardrobe`:衣櫃、`sofa`:沙發。可選擇多個設備,例如:option=tv,cold
Other string `url:"other,omitempty"` // 其他條件 - `cartplace`:有車位、`lift`:有電梯、`balcony_1`:有陽台、`cook`:可開伙、`pet`:可養寵物、`tragoods`:近捷運、`lease`:可短期租賃。可選擇多個條件,例如:other=cartplace,cook
FirstRow int `url:"firstRow"`
}

// HouseInfoCollection is the representation house information collection.
Expand Down

0 comments on commit 4423b9e

Please sign in to comment.