RCurl爬虫抓取验证码例子

抓取验证码

#1)抓取验证的流程
#①打开网页到验证码的位置

#②鼠标左键拖动验证

#③得到验证的url:http://tjcredit.gov.cn/verifycode?date=1461146339377
#④最后,把此url加入到R程序中
#⑤循环抓取验证码即可

#2)抓取一个验证码
library(RCurl)
## Warning: package 'RCurl' was built under R version 3.2.3
## Loading required package: bitops
#伪装报头
myHttpheader <- c("Accept"="image/webp,*/*;q=0.8","Accept-Encoding"="gzip,deflate,sdch","Accept-Language"="zh-CN,zh;q=0.8","Cache-Control"="no-cache","Connection"="keep-alive","Pragma"="no-cache","Referer"="http://bbs.shangdu.com/s/regform.htm","User-Agent"="Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36")

#获取验证码的url
url <- "http://tjcredit.gov.cn/verifycode?date=1461146339377"
png <- getBinaryURL(url, httpheader=myHttpheader)
writeBin(png, con="E:\\新技术\\爬虫\\验证码/111.png")
## NULL
#3)抓取N个验证码
for(i in 1:10) {
  #url <- "http://drops.wooyun.org/wooyun/captcha.php?"
  url1 <- "http://tjcredit.gov.cn/verifycode?date=1461145953254"
  png <- getBinaryURL(url1)
  file_name <- paste("E:\\新技术\\爬虫\\验证码/", i, ".png", sep="")
  writeBin(png, file_name)
}

你可能感兴趣的:(数据挖掘)