本文整理汇总了Golang中github.com/Unknwon/com.HttpGetBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang HttpGetBytes函数的具体用法?Golang HttpGetBytes怎么用?Golang HttpGetBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HttpGetBytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
log.Println("201402191")
client := &http.Client{}
p, err := com.HttpGetBytes(client, "http://godoc.org/-/index", nil)
if err != nil {
log.Fatalf("Fail to load page: %v", err)
}
content := string(p)
start := strings.Index(content, "<tbody>") + 7
end := strings.Index(content, "</tbody>")
content = content[start:end]
pkgs := strings.Split(content, "<tr>")[1:]
skipUntilIndex := 9052
endWhenIndex := 12000
for i, name := range pkgs {
if i < skipUntilIndex {
continue
} else if i == endWhenIndex {
break
}
name = strings.TrimSpace(name)[14:]
end := strings.Index(name, "\">")
name = name[:end]
log.Printf("#%d %s", i, name)
_, err = com.HttpGet(client, "https://gowalker.org/"+name, nil)
if err != nil {
log.Fatalf("Fail to load page: %v", err)
}
time.Sleep(0 * time.Second)
}
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:33,代码来源:crawl.go
示例2: TestJobsRegionsPaginate
func TestJobsRegionsPaginate(t *testing.T) {
pg := []struct {
from, to int
}{
{0, 1},
{0, 2},
{1, 4},
}
for _, page := range pg {
for _, reg := range regionsSample {
paginate := fmt.Sprintf("%s/jobs/regions/%s/%d/%d", ts.URL, reg.short, page.from, page.to)
b, err := com.HttpGetBytes(client, paginate, nil)
if err != nil {
t.Errorf("getting regions home page %v", err)
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(b)))
if err != nil {
t.Errorf("loading document %v", err)
}
s := doc.Find(".job-item")
d := page.to - page.from
if s.Length() != d {
t.Errorf("expected %d got %d", d, s.Length())
}
}
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:28,代码来源:base_test.go
示例3: TestDocsHome
//
//
// DOCS
//
//
func TestDocsHome(t *testing.T) {
l := fmt.Sprintf("%s/docs", ts.URL)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting docs home %v", err)
}
if !bytes.Contains(b, []byte("home.md")) {
t.Errorf("ecpectd docs home got %s", b)
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:15,代码来源:base_test.go
示例4: TestJobsRegionsHome
func TestJobsRegionsHome(t *testing.T) {
home := fmt.Sprintf("%s/jobs/regions", ts.URL)
b, err := com.HttpGetBytes(client, home, nil)
if err != nil {
t.Errorf("getting regions home page %v", err)
}
if !bytes.Contains(b, []byte(regionsSample[1].name)) {
t.Errorf("expected %s to contain %s", b, regionsSample[1].name)
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:10,代码来源:base_test.go
示例5: getGitTree
func getGitTree(url string) *gitTree {
p, err := com.HttpGetBytes(&http.Client{}, url, nil)
if err != nil {
log.Fatal(err)
}
var t gitTree
if err = json.Unmarshal(p, &t); err != nil {
log.Fatal(err)
}
return &t
}
开发者ID:hexiaochun,项目名称:gowalker,代码行数:11,代码来源:gen.go
示例6: TestJobsNewGet
func TestJobsNewGet(t *testing.T) {
l := fmt.Sprintf("%s/jobs/new", dashPath)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting dashboard home %v", err)
}
title := "<title>new job</title>"
if !bytes.Contains(b, []byte(title)) {
t.Errorf(" expected new job page got %s", b)
}
}
开发者ID:jwulf,项目名称:zedlist,代码行数:11,代码来源:dashboard_test.go
示例7: TestHome
//
//
// DASHBOARD
//
//
func TestHome(t *testing.T) {
l := fmt.Sprintf("%s/", dashPath)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting dashboard home %v", err)
}
title := "<title>dashboard</title>"
if !bytes.Contains(b, []byte(title)) {
t.Errorf(" expected login page got %s", b)
}
}
开发者ID:jwulf,项目名称:zedlist,代码行数:16,代码来源:dashboard_test.go
示例8: TestSetLang
func TestSetLang(t *testing.T) {
sw := fmt.Sprintf("%s/language/sw", ts.URL)
b, err := com.HttpGetBytes(client, sw, nil)
if err != nil {
t.Errorf("getting home page %v", err)
}
// Yes a home page should contain swahili words
if !bytes.Contains(b, []byte("nyumbani")) {
t.Errorf("expected home page to be in swahili got %s", b)
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:12,代码来源:base_test.go
示例9: getGoogleVCS
func getGoogleVCS(client *http.Client, match map[string]string) error {
// Scrape the HTML project page to find the VCS.
p, err := com.HttpGetBytes(client, com.Expand("http://code.google.com/p/{repo}/source/checkout", match), nil)
if err != nil {
return errors.New("doc.getGoogleVCS(" + match["importPath"] + ") -> " + err.Error())
}
m := googleRepoRe.FindSubmatch(p)
if m == nil {
return com.NotFoundError{"Could not VCS on Google Code project page."}
}
match["vcs"] = string(m[1])
return nil
}
开发者ID:nashtsai,项目名称:gopm,代码行数:13,代码来源:google.go
示例10: TestGetRegister
func TestGetRegister(t *testing.T) {
l := fmt.Sprintf("%s%s", ts.URL, registerPath)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting login page %v", err)
}
// The title of the page should be set to register
title := "<title>register</title>"
if !bytes.Contains(b, []byte(title)) {
t.Errorf(" expected login page got %s", b)
}
}
开发者ID:jwulf,项目名称:zedlist,代码行数:13,代码来源:local_test.go
示例11: getGolangRevision
func getGolangRevision(client *http.Client, n *Node) error {
match := map[string]string{}
{
m := golangPattern.FindStringSubmatch(n.ImportPath)
for i, n := range golangPattern.SubexpNames() {
if n != "" {
match[n] = m[i]
}
}
setupGoogleMatch(match)
}
match["repo"] = "go"
if len(n.Value) == 0 {
// Scrape the HTML project page to find the VCS.
p, err := com.HttpGetBytes(client, com.Expand("http://code.google.com/p/{repo}/source/checkout", match), nil)
if err != nil {
return fmt.Errorf("fail to fetch page: %v", err)
}
m := googleRepoRe.FindSubmatch(p)
if m == nil {
return fmt.Errorf("cannot find VCS on Google Code project page")
}
match["vcs"] = string(m[1])
n.Value = defaultTags[match["vcs"]]
}
match["tag"] = n.Value
data, err := com.HttpGetBytes(client, com.Expand("http://code.google.com/p/{repo}/source/browse/?repo={subrepo}&r={tag}", match), nil)
if err != nil {
return fmt.Errorf("fail to get revision(%s): %v", n.ImportPath, err)
}
m := googleRevisionPattern.FindSubmatch(data)
if m == nil {
return fmt.Errorf("cannot find revision in page: %s", n.ImportPath)
}
n.Revision = strings.TrimPrefix(string(m[0]), `_setViewedRevision('`)
n.ArchivePath = path.Join(setting.ArchivePath, n.ImportPath, n.Revision+".zip")
return nil
}
开发者ID:harryyeh,项目名称:switch,代码行数:39,代码来源:google.go
示例12: getGoogleVCS
func getGoogleVCS(client *http.Client, match map[string]string) error {
// Scrape the HTML project page to find the VCS.
p, err := com.HttpGetBytes(client, com.Expand("http://code.google.com/p/{repo}/source/checkout", match), nil)
if err != nil {
return fmt.Errorf("fail to fetch page: %v", err)
}
m := googleRepoRe.FindSubmatch(p)
if m == nil {
return com.NotFoundError{"Could not VCS on Google Code project page."}
}
match["vcs"] = string(m[1])
return nil
}
开发者ID:harryyeh,项目名称:switch,代码行数:13,代码来源:google.go
示例13: TestDocs
func TestDocs(t *testing.T) {
// with .md extension
l := fmt.Sprintf("%s/docs/home.md", ts.URL)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting docs home %v", err)
}
if !bytes.Contains(b, []byte("home.md")) {
t.Errorf("ecpectd docs home got %s", b)
}
// without .md extsnison
l = fmt.Sprintf("%s/docs/home", ts.URL)
b, err = com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting docs home %v", err)
}
if !bytes.Contains(b, []byte("home.md")) {
t.Errorf("ecpectd docs home got %s", b)
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:22,代码来源:base_test.go
示例14: getValidTLDs
// getValidTLDs gets and returns list of valid TLDs.
func getValidTLDs() (validTLDs []string) {
p, err := com.HttpGetBytes(&http.Client{}, "http://data.iana.org/TLD/tlds-alpha-by-domain.txt", nil)
if err != nil {
log.Fatal(err)
}
for _, line := range strings.Split(string(p), "\n") {
line = strings.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
continue
}
validTLDs = append(validTLDs, "."+strings.ToLower(line))
}
return validTLDs
}
开发者ID:hexiaochun,项目名称:gowalker,代码行数:16,代码来源:gen.go
示例15: TestJobsHome
func TestJobsHome(t *testing.T) {
home := fmt.Sprintf("%s/jobs/", ts.URL)
b, err := com.HttpGetBytes(client, home, nil)
if err != nil {
t.Errorf("getting home page %v", err)
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(b)))
if err != nil {
t.Errorf("loading document %v", err)
}
s := doc.Find(".job-item")
if s.Length() < 8 {
t.Errorf("expected 8 jobs got %d", s.Length())
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:15,代码来源:base_test.go
示例16: SiteFetchNewFeed
func SiteFetchNewFeed(siteId int64) error {
site, e := GetSite(siteId)
if e != nil {
return e
}
// exit if fetched recently
if !site.FeedFetched.IsZero() && time.Since(site.FeedFetched) < 5*time.Minute {
return nil
}
links, e := linkpreview.Articler.Index(site.Domain)
if e != nil {
return e
}
for _, link := range links {
if fetched, e := SiteLinkFetched(link); !fetched && e == nil {
color.Green("fetch %s", link)
cl := http.DefaultClient
cl.Timeout = 3 * time.Second
bts, e := com.HttpGetBytes(cl, link, http.Header{"User-Agent": {articler.HTTPUserAgent}})
if e != nil {
color.Red("%s", e)
continue
}
art, e := linkpreview.Articler.ParseArticle(link, bts)
if e != nil {
color.Red("%s", e)
continue
}
art.Text = string(bts)
sf := NewSiteFeedFromArticle(art)
sf.SiteId = siteId
e = SaveSiteFeed(sf)
if e != nil {
color.Red("%s", e)
continue
}
}
}
site.FeedFetched = time.Now()
return SaveSite(site)
//x.Where("created < ? and site_id = ?", time.Now().Truncate(5*time.Minute), siteId)
}
开发者ID:zhuharev,项目名称:smoljanin.ru,代码行数:47,代码来源:site_feed.go
示例17: getGithubRevision
func getGithubRevision(importPath string) (string, error) {
data, err := com.HttpGetBytes(Client, fmt.Sprintf("https://%s/commits/master", importPath), nil)
if err != nil {
return "", fmt.Errorf("fetch revision page: %v", err)
}
i := bytes.Index(data, []byte(`btn-outline`))
if i == -1 {
return "", errors.New("find revision locater: not found")
}
data = data[i+1:]
m := githubRevisionPattern.FindSubmatch(data)
if m == nil {
return "", fmt.Errorf("find revision: not found")
}
return strings.TrimPrefix(string(m[0]), `data-clipboard-text="`), nil
}
开发者ID:qiancy,项目名称:gowalker,代码行数:17,代码来源:github.go
示例18: TestLogout
func TestLogout(t *testing.T) {
l := fmt.Sprintf("%s%s", ts.URL, logoutPath)
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting login page %v", err)
}
// should redirect to home page
title := "<title>zedlist</title>"
if !bytes.Contains(b, []byte(title)) {
t.Errorf(" expected home page got %s", b)
}
// should not contain the logout button
outButton := "logout"
if bytes.Contains(b, []byte(outButton)) {
t.Errorf(" expected home page without logout button got %s", b)
}
}
开发者ID:jwulf,项目名称:zedlist,代码行数:18,代码来源:local_test.go
示例19: TestPostRegister
func TestPostRegister(t *testing.T) {
l := fmt.Sprintf("%s%s", ts.URL, registerPath)
vars := url.Values{
"first_name": {"geofrey"},
"last_name": {"enrnest"},
"middle_name": {"gernest"},
"email": {"[email protected]"},
"password": {"kilimahewa"},
"confirm_password": {"kilimahewa"},
"gender": {"1"},
"birth_date": {"2 January, 1980"},
}
// lets obtain the csrf_token to submit with the form.
b, err := com.HttpGetBytes(client, l, nil)
if err != nil {
t.Errorf("getting login page %v", err)
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(b)))
if err != nil {
t.Errorf("loading document %v", err)
}
token, ok := doc.Find("#token").Attr("value")
if !ok {
t.Errorf("expected crsf to ken to be set")
}
vars.Set("csrf_token", token)
resp, err := client.PostForm(l, vars)
if err != nil {
t.Errorf(" posting registration form %v", err)
}
defer resp.Body.Close()
buf := &bytes.Buffer{}
io.Copy(buf, resp.Body)
// SHould redirect to login page if registration is successful
// The title of the page should be set to login
title := "<title>login</title>"
if !bytes.Contains(buf.Bytes(), []byte(title)) {
t.Errorf(" expected login page got %s", buf)
}
}
开发者ID:jwulf,项目名称:zedlist,代码行数:43,代码来源:local_test.go
示例20: TestJobsRegionsByShortName
func TestJobsRegionsByShortName(t *testing.T) {
regs, err := query.GetAllRegions()
if err != nil {
t.Errorf("retriving regions %v", err)
}
for _, v := range regs {
regHome := fmt.Sprintf("%s/jobs/regions/%s", ts.URL, v.Short)
b, err := com.HttpGetBytes(client, regHome, nil)
if err != nil {
t.Errorf("getting regions home page %v", err)
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(b)))
if err != nil {
t.Errorf("loading document %v", err)
}
s := doc.Find(".job-item")
if s.Length() != 4 {
t.Errorf("expected 4 got %d", s.Length())
}
}
}
开发者ID:guus-vanweelden,项目名称:zedlist,代码行数:21,代码来源:base_test.go
注:本文中的github.com/Unknwon/com.HttpGetBytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论