Skip to content

Commit

Permalink
抽取出了公共类,成为单独的工程,以后任何地方都可用
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydenwen123 committed Jun 7, 2019
1 parent b4d4375 commit dac64ac
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 840 deletions.
237 changes: 0 additions & 237 deletions GolangSpider/common/HttpRequest.go

This file was deleted.

7 changes: 3 additions & 4 deletions GolangSpider/example/cbooo/cbooo.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package cbooo

import (
"GolangSpider/GolangSpider/common"
"GolangSpider/GolangSpider/util"
"encoding/csv"
"github.com/astaxie/beego/logs"
"github.com/jaydenwen123/go-util"
"os"
"regexp"
"strconv"
Expand All @@ -23,7 +22,7 @@ func Main() {
func SpiderMovieInfo(movieId string,downloadPoster bool) {
//1.发送请求
detailUrl:=getDetailUrl(movieId)
_, content := common.Request(detailUrl)
_, content := util.Request(detailUrl)
//fmt.Println(content)
//content=TrimSpace(content)
//fmt.Println(content)
Expand All @@ -44,7 +43,7 @@ func SpiderMovieInfo(movieId string,downloadPoster bool) {

func SpiderCboooHome() {
//1.发送http请求
_, content := common.Request(cboooUrl)
_, content := util.Request(cboooUrl)
//fmt.Println(content)
//解析CBO实时票房榜数据
SpiderBoxOffice(content)
Expand Down
2 changes: 1 addition & 1 deletion GolangSpider/example/cbooo/movie.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cbooo

import (
"GolangSpider/GolangSpider/util"
"github.com/jaydenwen123/go-util"
"strings"
)

Expand Down
7 changes: 3 additions & 4 deletions GolangSpider/example/gifshow/hot.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gifshow

import (
"GolangSpider/GolangSpider/common"
"GolangSpider/GolangSpider/example/kugou"
"GolangSpider/GolangSpider/util"
"github.com/jaydenwen123/GolangSpider/GolangSpider/example/kugou"
"github.com/jaydenwen123/go-util"
"fmt"
"github.com/astaxie/beego/logs"
"github.com/tidwall/gjson"
Expand Down Expand Up @@ -36,7 +35,7 @@ func DownloadWithBatch(epoch int) {

func DownloadHotVideo(id int,batch chan int) {
cost:=util.NewCost(time.Now())
jsonStr := common.RequestJsonWithPost(gifUrl, headers, bodyData)
jsonStr := util.RequestJsonWithPost(gifUrl, headers, bodyData)
//jsonStr:=SendPostRequest(url,headers,bodyData)
if !gjson.Valid(jsonStr){
logs.Error("获取json数据失败")
Expand Down
2 changes: 1 addition & 1 deletion GolangSpider/example/gushiwen/db/db.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package db

import (
"GolangSpider/GolangSpider/util"
"github.com/jaydenwen123/go-util"
"github.com/jinzhu/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion GolangSpider/example/gushiwen/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gushiwen

import (
"GolangSpider/GolangSpider/example/gushiwen/db"
"GolangSpider/GolangSpider/util"
"github.com/jaydenwen123/go-util"
"fmt"
"github.com/astaxie/beego/logs"
"io/ioutil"
Expand Down
11 changes: 5 additions & 6 deletions GolangSpider/example/gushiwen/shiwen.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gushiwen

import (
"GolangSpider/GolangSpider/common"
"github.com/jaydenwen123/go-util"
"GolangSpider/GolangSpider/example/gushiwen/db"
"GolangSpider/GolangSpider/util"
"github.com/PuerkitoBio/goquery"
"github.com/astaxie/beego/logs"
_ "github.com/jinzhu/gorm/dialects/postgres"
Expand All @@ -13,7 +12,7 @@ import (
//1.爬取古诗文网,诗文栏目的所有诗文类型,作者,朝代,形式(诗、词、曲、文言文)
//https://www.gushiwen.org/shiwen/
func SpiderShiwenKindUrl() ( map[string]string, map[string]string, map[string]string, map[string]string ) {
_, resp := common.Request(SHIWEN_URL)
_, resp := util.Request(SHIWEN_URL)
//fmt.Println(resp)
//util.TrimSpace(resp)
//利用正则表达式解析出所有的分类(类型、作者、朝代、形式)
Expand Down Expand Up @@ -60,7 +59,7 @@ func SpiderShiwenKindUrl() ( map[string]string, map[string]string, map[string]st
//2.1爬取不同类型诗文下的诗文链接
//<a href="/gushi/guiyuan.aspx">闺怨</a>
func SpiderShiwenByType(url string) []*db.Poem {
_, resp := common.Request(url)
_, resp := util.Request(url)
targets := util.MatchTarget(typePoemRe, resp)
curUrl:=""
poems:=make([]*db.Poem ,0)
Expand All @@ -76,7 +75,7 @@ func SpiderShiwenByType(url string) []*db.Poem {
//2.2爬取不同类型诗文下的诗文链接
//<a href="/gushi/guiyuan.aspx">闺怨</a>
func SpiderShiwenUrlByType(url string) []string {
_, resp := common.Request(url)
_, resp := util.Request(url)
targets := util.MatchTarget(typePoemRe, resp)
curUrl:=""
urls:=make([]string,0)
Expand All @@ -93,7 +92,7 @@ func SpiderShiwenUrlByType(url string) []string {
//原文、译文、注释、背景、赏析、作者介绍
func SpiderShiwenContent(shiwenUrl string) *db.Poem {
poem:=&db.Poem{}
reader := common.ResponseWithReader(shiwenUrl)
reader := util.ResponseWithReader(shiwenUrl)
//采用新的方案来解决
//https://github.com/PuerkitoBio/goquery
doc, err := goquery.NewDocumentFromReader(reader)
Expand Down
2 changes: 1 addition & 1 deletion GolangSpider/example/juejin/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package juejin

import (
"GolangSpider/GolangSpider/util"
"github.com/jaydenwen123/go-util"
"fmt"
"testing"
)
Expand Down
Loading

0 comments on commit dac64ac

Please sign in to comment.