change goquery.NewDocument deprecated method and add language header
This commit is contained in:
parent
7c9eb133e8
commit
1c49fea3ef
1 changed files with 18 additions and 1 deletions
19
profile.go
19
profile.go
|
|
@ -2,6 +2,7 @@ package twitterscraper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -29,7 +30,23 @@ type Profile struct {
|
||||||
// GetProfile return parsed user profile
|
// GetProfile return parsed user profile
|
||||||
func GetProfile(username string) (Profile, error) {
|
func GetProfile(username string) (Profile, error) {
|
||||||
url := "https://twitter.com/" + username
|
url := "https://twitter.com/" + username
|
||||||
doc, err := goquery.NewDocument(url)
|
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return Profile{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept-Language", "en-US")
|
||||||
|
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
|
||||||
|
if res == nil {
|
||||||
|
return Profile{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Profile{}, err
|
return Profile{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue