本文整理匯總了Golang中github.com/moovweb/gokogiri/html.HtmlDocument.DocPtr方法的典型用法代碼示例。如果您正苦於以下問題:Golang HtmlDocument.DocPtr方法的具體用法?Golang HtmlDocument.DocPtr怎麽用?Golang HtmlDocument.DocPtr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/moovweb/gokogiri/html.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.DocPtr方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processOffJoins
func (record *Record) processOffJoins(doc *html.HtmlDocument) {
xPath := xpath.NewXPath(doc.DocPtr())
// join the offence with the defendants and verdict
joinPtrs := xPath.Evaluate(doc.Root().NodePtr(),
xpath.Compile("//join[@result='criminalCharge']"))
for _, nodePtr := range joinPtrs {
node := xml.NewNode(nodePtr, doc)
targets := strings.Split(node.Attr("targets"), " ")
var personId, offId, verdictId string
for _, targetId := range targets {
if strings.Contains(targetId, "defend") {
personId = targetId
}
if strings.Contains(targetId, "off") {
offId = targetId
}
if strings.Contains(targetId, "verdict") {
verdictId = targetId
}
}
offence := record.findOffence(offId)
if offence == nil {
panic("couldn't find offence " + offId)
}
person := record.findPerson(personId)
if person != nil {
offence.Defendants = append(offence.Defendants, person)
}
verdict := record.findVerdict(verdictId)
if verdict != nil {
offence.Verdict = verdict
}
}
}
示例2: getInterp
// get the value out of an <interp> tag
func getInterp(basePtr unsafe.Pointer, interpType string, doc *html.HtmlDocument) (value string) {
xPath := xpath.NewXPath(doc.DocPtr())
nodePtrs := xPath.Evaluate(basePtr, xpath.Compile(".//interp[@type='"+
interpType+"']"))
if len(nodePtrs) == 1 {
node := xml.NewNode(nodePtrs[0], doc)
value = node.Attr("value")
}
return
}
示例3: processVerdicts
func (record *Record) processVerdicts(doc *html.HtmlDocument) {
xPath := xpath.NewXPath(doc.DocPtr())
verdictPtrs := xPath.Evaluate(doc.Root().NodePtr(),
xpath.Compile("//rs[@type='verdictDescription']"))
verdicts := make([]Verdict, len(verdictPtrs))
for i, nodePtr := range verdictPtrs {
node := xml.NewNode(nodePtr, doc)
verdict := Verdict{}
verdict.Id = node.Attr("id")
verdict.Desc = cleanUpContent(node.Content())
verdict.SetType(getInterp(nodePtr, "verdictCategory", doc))
verdicts[i] = verdict
}
record.Verdicts = verdicts
}
示例4: processOffences
func (record *Record) processOffences(doc *html.HtmlDocument) {
xPath := xpath.NewXPath(doc.DocPtr())
offencePtrs := xPath.Evaluate(doc.Root().NodePtr(),
xpath.Compile("//rs[@type='offenceDescription']"))
offences := make([]Offence, len(offencePtrs))
for i, nodePtr := range offencePtrs {
node := xml.NewNode(nodePtr, doc)
offence := Offence{}
offence.Id = node.Attr("id")
offence.Category = getInterp(nodePtr, "offenceCategory", doc)
offence.SubCategory = getInterp(nodePtr, "offenceSubcategory", doc)
offence.Desc = cleanUpContent(node.Content())
offences[i] = offence
}
record.Offences = offences
}
示例5: processPersons
func (record *Record) processPersons(doc *html.HtmlDocument) {
xPath := xpath.NewXPath(doc.DocPtr())
personPtrs := xPath.Evaluate(doc.Root().NodePtr(),
xpath.Compile("//persname"))
persons := make([]Person, len(personPtrs))
for i, nodePtr := range personPtrs {
node := xml.NewNode(nodePtr, doc)
person := Person{}
person.Id = node.Attr("id")
person.GivenName = getInterp(nodePtr, "given", doc)
person.Surname = getInterp(nodePtr, "surname", doc)
person.SetType(node.Attr("type"))
person.SetGender(getInterp(nodePtr, "gender", doc))
persons[i] = person
}
record.Persons = persons
}