Merge master with fixed test
This commit is contained in:
commit
83a9382e99
2 changed files with 29 additions and 11 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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetProfile(t *testing.T) {
|
func TestGetProfile(t *testing.T) {
|
||||||
joined := time.Unix(1245860880, 0)
|
loc := time.FixedZone("UTC", 0)
|
||||||
|
joined := time.Date(2007,02, 20,6,35,0,0, loc)
|
||||||
sample := Profile{
|
sample := Profile{
|
||||||
Avatar: "https://pbs.twimg.com/profile_images/1176439369596624896/Fkqe6qVj_400x400.jpg",
|
Avatar: "https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png",
|
||||||
Biography: "Kenneth Reitz, n: a garden–variety self–referential loop. Not available for purchase. Made in USA.",
|
Biography: "What’s happening?!",
|
||||||
Birthday: "1988",
|
Birthday: "March 21",
|
||||||
Joined: &joined,
|
Joined: &joined,
|
||||||
Location: "Eden, Earth, Milky Way",
|
Location: "Everywhere",
|
||||||
Name: "☿ Kenneth Reitz",
|
Name: "Twitter",
|
||||||
URL: "https://twitter.com/kennethreitz",
|
URL: "https://twitter.com/Twitter",
|
||||||
Username: "kennethreitz",
|
Username: "Twitter",
|
||||||
Website: "https://kennethreitz.org/values",
|
Website: "https://about.twitter.com/",
|
||||||
}
|
}
|
||||||
|
|
||||||
profile, err := GetProfile("kennethreitz")
|
profile, err := GetProfile("Twitter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue