单机版爬虫,珍爱网。爬取用户信息时403报错

来源:15-9 用户信息解析器(下)

nitros

2020-02-07

老师好!

城市列表及城市页面下的用户列表都能正常爬取。fetcher。go和engine。go的设定应该都没问题

但是用户页面下要爬取信息时,页面访问报错403,不能正常得到res.body内容。
请问老师类似问题应该如何解决啊

代码如下:

package parser

import (
“goImooc/crawler/engine”
“log”
“regexp”
)

const itemRe = <div class="des f-cl" data-v-3c42fade>([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^<]*)</div>

func itemData(contents []byte) engine.ParserResult {
log.Println("contents is : " + string(contents))
compile := regexp.MustCompile(itemRe)
all := compile.FindAllSubmatch(contents, -1)

//profile := model.Profile{}
result := engine.ParserResult{}

for _, pro := range all {
	log.Println("profile:" + string(pro[1]))
	//profile.Age = string(pro[2])
	//profile.Degree = string(pro[3])
	//profile.Marriage = string(pro[4])
	//profile.Height = string(pro[5])
	//profile.Income = string(pro[6])
	//result.Items = append(result.Items, engine.ParserResult{
	//	Items:    profile,
	//})
}

return result

}

报错内容示例如下:

2020/02/07 15:51:46 Got item: Name: 草木
2020/02/07 15:51:46 Got item: Name: 好好爱自己
2020/02/07 15:51:49 wrong is statuscode: 403
2020/02/07 15:51:49 parsering url: http://album.zhenai.com/u/1685148615
2020/02/07 15:51:49 contents is :

403 Forbidden

403 Forbidden


nginx

2020/02/07 15:51:49 profile:

写回答

1回答

ccmouse

2020-02-09

对方现在技术升级了,会拦下我们这种可疑的机器人。可以降低爬取速率,换http头部的user-agent等来缓解。

请参考我的

14-2 爬虫的法律风险 

14-3 新爬虫的选择 

这两节。

0
1
nitros
非常感谢!
2020-02-12
共1条回复

Google资深工程师深度讲解Go语言 由浅入深掌握Go语言

语法+分布式爬虫实战 为转型工程师量身打造

5995 学习 · 1909 问题

查看课程