mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
rewriting readability
This commit is contained in:
parent
ac36892150
commit
82586dedff
@ -22,7 +22,7 @@ func InnerHTML(node *html.Node) string {
|
|||||||
|
|
||||||
func Attr(node *html.Node, key string) string {
|
func Attr(node *html.Node, key string) string {
|
||||||
for _, a := range node.Attr {
|
for _, a := range node.Attr {
|
||||||
if a.Key == key {
|
if strings.EqualFold(a.Key, key) {
|
||||||
return a.Val
|
return a.Val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ func scoreNode(s *goquery.Selection) *candidate {
|
|||||||
c.score -= 5
|
c.score -= 5
|
||||||
}
|
}
|
||||||
|
|
||||||
c.score += getClassWeight(s)
|
c.score += getClassWeight(s.Get(0))
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,10 +267,10 @@ func getLinkDensity(s *goquery.Selection) float32 {
|
|||||||
|
|
||||||
// Get an elements class/id weight. Uses regular expressions to tell if this
|
// Get an elements class/id weight. Uses regular expressions to tell if this
|
||||||
// element looks good or bad.
|
// element looks good or bad.
|
||||||
func getClassWeight(s *goquery.Selection) float32 {
|
func getClassWeight(node *html.Node) float32 {
|
||||||
weight := 0
|
weight := 0
|
||||||
class, _ := s.Attr("class")
|
class := htmlutil.Attr(node, "class")
|
||||||
id, _ := s.Attr("id")
|
id := htmlutil.Attr(node, "id")
|
||||||
|
|
||||||
if class != "" {
|
if class != "" {
|
||||||
if negativeRegexp.MatchString(class) {
|
if negativeRegexp.MatchString(class) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user