This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,887 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,18 @@ | ||
package ZhihuZhuanlanCrawler | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"github.com/imroc/req" | ||
) | ||
|
||
type Client struct { | ||
client *http.Client | ||
} | ||
|
||
func NewClient(httpClient *http.Client) *Client { | ||
if httpClient == nil { | ||
httpClient = &http.Client{} | ||
} | ||
|
||
c := &Client{ | ||
client: httpClient, | ||
} | ||
|
||
return c | ||
} | ||
|
||
func (c *Client) SendNewZhihuRequest(u string) ([]byte, error) { | ||
req, err := http.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36") | ||
req.Header.Add("Host", "zhuanlan.zhihu.com") | ||
req.Header.Add("Referer", "https://zhuanlan.zhihu.com/") | ||
|
||
res, err := c.client.Do(req) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, err | ||
} | ||
|
||
defer res.Body.Close() | ||
func sendNewZhihuRequest(u string) ([]byte, error) { | ||
r, err := req.Get(u, req.Header{ | ||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36", | ||
"Referer": "https://zhuanlan.zhihu.com/", | ||
}, nil) | ||
|
||
bodyByte, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
log.Println(err) | ||
return nil, err | ||
} | ||
|
||
return bodyByte, nil | ||
return r.ToBytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/solarhell/ZhihuZhuanlanCrawler | ||
|
||
go 1.12 | ||
|
||
require github.com/imroc/req v0.2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/imroc/req v0.2.4 h1:8XbvaQpERLAJV6as/cB186DtH5f0m5zAOtHEaTQ4ac0= | ||
github.com/imroc/req v0.2.4/go.mod h1:J9FsaNHDTIVyW/b5r6/Df5qKEEEq2WzZKIgKSajd1AE= |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.