Answer the question
In order to leave comments, you need to log in
How to parse html code inside title?
Given the html code, available at the link:
<div name="lesson" class="lesson" title="
<p class=tooltip_name><b>1-1</b></p>
<p class=tooltip_professor>Преп2</p>
<hr />
<p class=tooltip_aud>Практическое занятие</p>
" style="background-color: #D5F6FF;">
<p>Физ культура</p>
<p class="lesson_aud">ЗАЛ1</p>
</div>
teacher, err := td.Find(".lesson").Attr("title") // получает значение title
if err != true {
log.Fatal(err)
}
teacher= ClearSpace(teacher) // удаляет и обрезает лишние пробелы
fmt.Println(teacher + "\n")
<p class=tooltip_name><b>1-1</b></p> <p class=tooltip_professor>Преп2</p> <hr /> <p class=tooltip_aud>Практическое занятие</p>
Answer the question
In order to leave comments, you need to log in
You just need to parse the html again
package main
import (
"bytes"
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
)
func main() {
rawHtml := bytes.NewBuffer([]byte(`
<div name="lesson" class="lesson" title="
<p class=tooltip_name><b>1-1</b></p>
<p class=tooltip_professor>Преп2</p>
<hr />
<p class=tooltip_aud>Практическое занятие</p>
" style="background-color: #D5F6FF;">
<p>Физ культура</p>
<p class="lesson_aud">ЗАЛ1</p>
</div>
`))
doc, err := goquery.NewDocumentFromReader(rawHtml)
if err != nil {
log.Fatal(err)
}
title, ok := doc.Find(".lesson").Attr("title") // получаем значение title
if !ok {
log.Fatal("Cannot find the node with the class 'lesson'")
}
// Парсим то, что лежит в title
docFromTitle, err := goquery.NewDocumentFromReader(bytes.NewBuffer([]byte(title)))
if err != nil {
log.Fatal(err)
}
// Получаем элемент с именем преподавателя
teacher := docFromTitle.Find(".tooltip_professor").Text()
fmt.Println(teacher)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question