refactor: move WebGetTitle inside measurexlite (#895)
Part of https://github.com/ooni/probe/issues/2240
This commit is contained in:
parent
bb6563f363
commit
7c1b2bbcb0
5 changed files with 88 additions and 17 deletions
19
internal/measurexlite/web.go
Normal file
19
internal/measurexlite/web.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package measurexlite
|
||||
|
||||
//
|
||||
// Code to process web results (e.g., from web connectivity)
|
||||
//
|
||||
|
||||
import "regexp"
|
||||
|
||||
// WebGetTitle returns the title or an empty string.
|
||||
func WebGetTitle(measurementBody string) string {
|
||||
// MK used {1,128} but we're making it larger here to get longer titles
|
||||
// e.g. <http://www.isa.gov.il/Pages/default.aspx>'s one
|
||||
re := regexp.MustCompile(`(?i)<title>([^<]{1,512})</title>`)
|
||||
v := re.FindStringSubmatch(measurementBody)
|
||||
if len(v) < 2 {
|
||||
return ""
|
||||
}
|
||||
return v[1]
|
||||
}
|
||||
Loading…
Reference in a new issue