rent

package module
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 11 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fiveN1 Rent Scraper

logo

CI Go Report Card GoDoc

a.k.a 591 rent scraper.

Easy scraping 591 rent information.

Installation

$ make install

Usage

package main

import (
	"log"

	rent "github.com/neighborhood999/fiveN1-rent-scraper"
)

func main() {
	options := rent.NewOptions()
	url, err := rent.GenerateURL(options)
	if err != nil {
		log.Fatalf("\x1b[91;1m%s\x1b[0m", err)
	}

	f := rent.NewFiveN1(url)
	if err := f.Scrape(1); err != nil {
		log.Fatal(err)
	}

	json := rent.ConvertToJSON(f.RentList)
	log.Println(string(json))
}

And output json:

{
  "1": [
    {
      "preview":
        "https://hp1.591.com.tw/house/active/2013/11/04/138356961541004002_765x517.water3.jpg",
      "title": "松山路套房 * 交通方便近捷運後山埤站 *",
      "url": "https://rent.591.com.tw/rent-detail-5857738.html",
      "address": "信義區 - 松山路 119 巷",
      "rentType": "沒有格局說明",
      "optionType": "獨立套房",
      "ping": "6",
      "floor": "樓層:3/4",
      "price": "9,000 元 / 月",
      "isNew": true
    }
  ]
}

Index number is the representation page number, every index contain 30 items. 🏠

Options

Create and generate URL by options:

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:

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`:別墅
	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"`
}

For example:

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

rent.GenerateURL(options)

Multiple Pages

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

f := rent.NewFiveN1(url)
f.Scrape(5) // page.1 to page.5

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

Code Lists

LICENSE

MIT © Peng Jie

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToJSON

func ConvertToJSON(list HouseInfoCollection) []byte

ConvertToJSON is convert rent house info collection to json.

func ExportJSON

func ExportJSON(b []byte)

ExportJSON export json file.

func GenerateURL

func GenerateURL(o *Options) (string, error)

GenerateURL is convert options to query parameters.

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is the representation goquery.Document.

func NewDocument

func NewDocument() *Document

NewDocument create a `Document` with default value.

type FiveN1

type FiveN1 struct {
	TotalPages int

	RentList HouseInfoCollection
	// contains filtered or unexported fields
}

FiveN1 is the representation page information.

func NewFiveN1

func NewFiveN1(url string) *FiveN1

NewFiveN1 create a `FiveN1` with default value.

func (*FiveN1) GetTotalPage

func (f *FiveN1) GetTotalPage() int

GetTotalPage can use get total page

func (*FiveN1) Scrape

func (f *FiveN1) Scrape(page int) error

Scrape will clone entire DOM for reuse. It will scrape first page at first, if specify page number > 1, it will start workers.

func (*FiveN1) SetReqCookie

func (f *FiveN1) SetReqCookie(region string)

SetReqCookie set the region value.

type HouseInfo

type HouseInfo struct {
	Preview    string `json:"preview"`
	Title      string `json:"title"`
	URL        string `json:"url"`
	Address    string `json:"address"`
	RentType   string `json:"rentType"`
	OptionType string `json:"optionType"`
	Ping       string `json:"ping"` // a.k.a 坪數
	Floor      string `json:"floor"`
	Price      string `json:"price"`
	IsNew      bool   `json:"isNew"`
}

HouseInfo is the representation rent house information.

func NewHouseInfo

func NewHouseInfo() *HouseInfo

NewHouseInfo create a new `HouseInfo`.

type HouseInfoCollection

type HouseInfoCollection map[int][]*HouseInfo

HouseInfoCollection is the representation house information collection.

type Options

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`:別墅
	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"`
}

Options is the representation query argument.

func NewOptions

func NewOptions() *Options

NewOptions create a `Options` with default value.

Directories

Path Synopsis
_example
api-server command
basic command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址