#139·goquery

<noscript> causes selector to fail

Author: nathan-osmanCreated Dec 5, 2016Updated Jul 29, 2021

Consider the following program:

go
package main

import (
	"fmt"
	"strings"

	"github.com/PuerkitoBio/goquery"
)

const data = `<noscript><a href="http://example.org">click this link</a></noscript>`

func main() {
	d, err := goquery.NewDocumentFromReader(strings.NewReader(data))
	if err != nil {
		fmt.Println(err)
		return
	}
	a, ok := d.Find("noscript a").Attr("href")
	fmt.Printf("URL: '%s', %t\n", a, ok)
}

The expected output is:

URL: 'http://example.org', true

But instead the output is:

URL: '', false

Changing noscript to div in both the document and selector causes the expected output, so the problem seems to affect only <noscript> elements.