因为PPBC的防盗链,尝试用vba的对象来解决,顺便复习一下。。。
2015-12-15 23:59
567 查看
由于PPBC的防盗链,从其他网站打开图片链接:
http://img.plantphoto.cn/image2/b/351969.jpg
你不会看到图片的真是内容,此时需要设置referer
当尝试添加referer之后还是没用。
后来发现使用的是xmlhttp对象,而xmlhttp设置referer是无效的,于是改用winhttp对象,成功。
Sub test()
For i = 1 To 10
a = "http://www.plantphoto.cn"
a2 = Cells(i, 1).Value 'http://img.plantphoto.cn/image2/b/351969.jpg
Set ie = CreateObject("WinHttp.WinHttpRequest.5.1")
ie.Open "GET", a2, False
ie.setRequestHeader "Referer", a
ie.Send
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.write ie.Responsebody
.savetofile ThisWorkbook.Path & "\" & i & ".jpg", 2
.Close
End With
'Set ie = Nothing
Next
MsgBox "over"
End Sub
http://img.plantphoto.cn/image2/b/351969.jpg
你不会看到图片的真是内容,此时需要设置referer
当尝试添加referer之后还是没用。
后来发现使用的是xmlhttp对象,而xmlhttp设置referer是无效的,于是改用winhttp对象,成功。
Sub test()
For i = 1 To 10
a = "http://www.plantphoto.cn"
a2 = Cells(i, 1).Value 'http://img.plantphoto.cn/image2/b/351969.jpg
Set ie = CreateObject("WinHttp.WinHttpRequest.5.1")
ie.Open "GET", a2, False
ie.setRequestHeader "Referer", a
ie.Send
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.write ie.Responsebody
.savetofile ThisWorkbook.Path & "\" & i & ".jpg", 2
.Close
End With
'Set ie = Nothing
Next
MsgBox "over"
End Sub
相关文章推荐
- vb常用函数一览表
- Excel VBA简单使用——数据缺失处理
- VB中PictureBox控件使用教程
- vbScript 备忘
- VBA 中 do-loop,do-while-loop,do-until-loop,for-each-next 的小例子
- stm32F103VB使用uGfx驱动sh1106
- 《VB语言程序设计(第3版)》总结
- 高中信息技术《算法与程序设计VB(选修)》知识要点
- 关于vb代码复制到其他地方出现乱码的问题
- VBCodeProvider .net compiler service interface or something like that
- 最新Viking(维金)病毒专杀工具,纯VB编写。
- VBS 改 IP(modify IP by VBS)
- VBA 笔记
- VB编译器计划重启(唠叨篇)
- 用VBA实现批量数据填充到word模板
- word2007无法使用宏的解决方法-设置宏与安装VBA组件
- 利用VBA遍历Excel所有sheet的例子
- 利用VBA导出文件的例子
- 利用VBA批量给Excel添加超链接
- vb2016