mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 01:15:57 -06:00
Separate parsing into parse.go, add separate VIP get
This commit is contained in:
63
api.go
63
api.go
@@ -178,32 +178,54 @@ func GetForm(id uint) GetFormResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if this form is a VIP property
|
// Check if this form is a VIP property
|
||||||
guestCodeInput := doc.Find("div.form-group > input#guestCode").First()
|
if CheckGuestCodeRequired(doc) {
|
||||||
if guestCodeInput.Length() == 1 {
|
|
||||||
log.Debugf("Guest Code input: %v", guestCodeInput)
|
|
||||||
log.Debug("Guest Code form detected")
|
|
||||||
return GetFormResult{
|
return GetFormResult{
|
||||||
requireGuestCode: true,
|
requireGuestCode: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the hidden inputs & form fields
|
// Get the hidden inputs & form fields
|
||||||
hiddenInputs := make([]string, 0, 5)
|
formFields, hiddenInputs := GetFields(doc)
|
||||||
formFields := make([]Field, 0, 5)
|
|
||||||
doc.Find("#property-name-form > input[type=hidden]").Each(func(i int, s *goquery.Selection) {
|
// Acquire the title/address
|
||||||
hiddenInputs = append(hiddenInputs, s.AttrOr("id", ""))
|
titleElement := doc.Find("div > div > h4").First()
|
||||||
})
|
title := titleElement.Text()
|
||||||
doc.Find("#property-name-form > div.form-group").Each(func(i int, s *goquery.Selection) {
|
address := strings.TrimSpace(titleElement.Next().Text())
|
||||||
input := s.Find("input.form-control").First()
|
|
||||||
label := s.Find("label").First().Text()
|
return GetFormResult{
|
||||||
|
propertyName: title,
|
||||||
inputId, _ := input.Attr("id")
|
address: address,
|
||||||
|
fields: formFields,
|
||||||
formFields = append(formFields, Field{
|
hiddenInputs: hiddenInputs,
|
||||||
text: label,
|
}
|
||||||
id: inputId,
|
}
|
||||||
})
|
|
||||||
})
|
func GetVipForm(id uint, guestCode string) GetFormResult {
|
||||||
|
body := fmt.Sprintf("propertyIdSelected=%d&propertySource=parking-snap&guestCode=%s", id, guestCode)
|
||||||
|
req := BuildRequestWithBody("POST", "/register-get-vehicle-form", nil, bytes.NewBufferString(body))
|
||||||
|
SetTypicalHeaders(req, nil, nil, false)
|
||||||
|
onRequest(req)
|
||||||
|
|
||||||
|
res, _ := client.Do(req)
|
||||||
|
onResponse(res)
|
||||||
|
|
||||||
|
html, _ := io.ReadAll(res.Body)
|
||||||
|
htmlString := string(html)
|
||||||
|
|
||||||
|
if htmlString == "guest-code" {
|
||||||
|
return GetFormResult{
|
||||||
|
requireGuestCode: true,
|
||||||
|
err: fmt.Errorf("guest code is invalid"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, err := goquery.NewDocumentFromReader(bytes.NewBufferString(htmlString))
|
||||||
|
if err != nil {
|
||||||
|
return GetFormResult{err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the hidden inputs & form fields
|
||||||
|
formFields, hiddenInputs := GetFields(doc)
|
||||||
|
|
||||||
// Acquire the title/address
|
// Acquire the title/address
|
||||||
titleElement := doc.Find("div > div > h4").First()
|
titleElement := doc.Find("div > div > h4").First()
|
||||||
@@ -215,6 +237,5 @@ func GetForm(id uint) GetFormResult {
|
|||||||
address: address,
|
address: address,
|
||||||
fields: formFields,
|
fields: formFields,
|
||||||
hiddenInputs: hiddenInputs,
|
hiddenInputs: hiddenInputs,
|
||||||
requireGuestCode: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
parse.go
Normal file
33
parse.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/PuerkitoBio/goquery"
|
||||||
|
|
||||||
|
// CheckGuestCodeRequired checks whether the guest code is required to access the property.
|
||||||
|
// This is done by checking whether the guest code input field exists on the page.
|
||||||
|
// This function is pretty experimental as I am still unsure how the guest code is handled on a property by property basis.
|
||||||
|
func CheckGuestCodeRequired(doc *goquery.Document) bool {
|
||||||
|
return doc.Find("div.form-group > input#guestCode").Length() > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFields(doc *goquery.Document) ([]Field, []string) {
|
||||||
|
hiddenInputs := make([]string, 0, 5)
|
||||||
|
formFields := make([]Field, 0, 5)
|
||||||
|
|
||||||
|
doc.Find("#property-name-form > input[type=hidden]").Each(func(i int, s *goquery.Selection) {
|
||||||
|
hiddenInputs = append(hiddenInputs, s.AttrOr("id", ""))
|
||||||
|
})
|
||||||
|
|
||||||
|
doc.Find("#property-name-form > div.form-group").Each(func(i int, s *goquery.Selection) {
|
||||||
|
input := s.Find("input.form-control").First()
|
||||||
|
label := s.Find("label").First().Text()
|
||||||
|
|
||||||
|
inputId, _ := input.Attr("id")
|
||||||
|
|
||||||
|
formFields = append(formFields, Field{
|
||||||
|
text: label,
|
||||||
|
id: inputId,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return formFields, hiddenInputs
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user