怎么看哪些python 爬取链接的链接是攻击的

你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。2009年7月 总版技术专家分月排行榜第二2009年3月 总版技术专家分月排行榜第二2009年1月 总版技术专家分月排行榜第二2005年7月 总版技术专家分月排行榜第二2005年5月 总版技术专家分月排行榜第二2005年3月 总版技术专家分月排行榜第二
优秀小版主2015年8月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2015年2月论坛优秀版主
2012年12月 总版技术专家分月排行榜第一2012年10月 总版技术专家分月排行榜第一2012年9月 总版技术专家分月排行榜第一2012年8月 总版技术专家分月排行榜第一
2012年11月 总版技术专家分月排行榜第三
2011年 总版技术专家分年内排行榜第三2010年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第五
2011年 总版技术专家分年内排行榜第三2010年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第五
2011年 总版技术专家分年内排行榜第三2010年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第五
2009年7月 总版技术专家分月排行榜第二2009年3月 总版技术专家分月排行榜第二2009年1月 总版技术专家分月排行榜第二2005年7月 总版技术专家分月排行榜第二2005年5月 总版技术专家分月排行榜第二2005年3月 总版技术专家分月排行榜第二
优秀小版主2015年8月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2015年2月论坛优秀版主
本帖子已过去太久远了,不再提供回复功能。刚开始爬取的时候是用正则表达式实现的,然后爬取了不必要的链接,现在改用goquery实现:
// judgeUrl project judgeUrl.go
package judgeUrl
func IsUrl(str string) bool {
if strings.HasPrefix(str, &#&) || strings.HasPrefix(str, &//&) || strings.HasSuffix(str, &.exe&) || strings.HasSuffix(str, &:void(0);&) {
return false
} else if strings.HasPrefix(str, &{&) && strings.HasSuffix(str, &}&) {
return false
} else if strings.EqualFold(str, &javascript:;&) {
return false
return true
return true
func SamePathUrl(preUrl string, url string, mark int) (newUrl string) {
last := strings.LastIndex(preUrl, &/&)
if last == 6 {
newUrl = preUrl + url
if mark == 1 {
newUrl = preUrl[:last] + url
newPreUrl := preUrl[:last]
newLast := strings.LastIndex(newPreUrl, &/&)
newUrl = newPreUrl[:newLast] + url
return newUrl
// WebUrls_Spider project main.go
package main
&/PuerkitoBio/goquery&
&test/judgeUrl&
var urlMap map[string]bool //防止重复链接进入死循环,不过获取链接太多可能会内存溢出
func fetch(url string, count int) {
if count & 1 { //设定爬取深度是1页
body, err := goquery.NewDocument(url)
if err != nil {
body.Find(&a&).Each(func(i int, aa *goquery.Selection) {
href, IsExist := aa.Attr(&href&)
if IsExist == true {
href = strings.TrimSpace(href)
if len(href) & 2 && judgeUrl.IsUrl(href) {
if _, ok := urlMap[href]; ok == false {
fmt.Println(&之前的url:&, href)
if strings.HasPrefix(href, &/&) || strings.HasPrefix(href, &./&) {
href = judgeUrl.SamePathUrl(url, href, 1)
} else if strings.HasPrefix(href, &../&) {
href = judgeUrl.SamePathUrl(url, href, 2)
fmt.Println(&修改之后的url:&, href)
urlMap[href] = true
fetch(href, count+1)
func writeValues(outfile string) error {
file, err := os.Create(outfile)
if err != nil {
fmt.Printf(&创建%s文件失败!&, outfile)
return err
defer file.Close()
for k, _ := range urlMap {
file.WriteString(k + &\n&)
return nil
func main() {
urlMap = make(map[string]bool, 1000000)
fetch(&/&, 0)
writeValues(&urls.dat&)
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:318528次
积分:7621
积分:7621
排名:第2564名
原创:456篇
评论:39条
(2)(1)(2)(4)(8)(1)(1)(1)(6)(6)(21)(52)(22)(12)(25)(28)(29)(17)(16)(25)(73)(80)(32)网络爬虫应该怎么抓取调用JS函数的链接地址
代码示例:
&a href = "javascript:test('test');"&test&/a&
类似如上形式的代码,我应该怎么抓取链接地址。
貌似木有啥好的办法,针对特定网页人工分析js代码,然后爬取。
可以使用phantomjs 做模拟点击
jsoup或htmlparser进行解析,&a ....&,获取href属性值即可。
如果需要点击,建议使用htmlunit
写爬虫的童鞋可以试试神箭手云爬虫,自带JS渲染、代理ip、验证码识别等功能,还可以发布和导出爬取的数据,生成图表等,都在云端进行,不需要安装开发环境。

我要回帖

更多关于 scrapy 爬取全站链接 的文章

 

随机推荐