|
各位大佬晚上好,首先祝大家元旦快乐希望大佬可以抽出宝贵的时间帮我解决一下这个问题
现在手里有几万张图片需要转换成链接,所以我现在想上传这些图片到这个网址网址:https://666666.imgbb.com/
用户名:666666
密码:123123abc
自己已经研究了两天了,不知道怎么办
已经从 http://club.excelhome.net/thread-1159783-1-1.html 这个大佬的帖子中学习过了,可还是上传的时候显示该页面不存在
我使用了这一段代码:
--------------------------------------------------------------------------------------
Sub Main()
Const Uid As String = "" '论坛UID
Const Hash As String = "" '上传的Hash,从Fiddler里取
Dim Boundary As String
Dim SendData
Dim FileFullName As String
Dim FileShortName As String
Dim Title As String
Dim Filetype As String
FileFullName = "D:\测试2.rar"
FileShortName = Mid(FileFullName, InStrRev(FileFullName, "") + 1)
Title = Left(FileShortName, InStrRev(FileShortName, ".") - 1)
Filetype = "rar"
'获取Boundary
Boundary = GetBoundary()
'获取上传所需的SendData
SendData = GetUpLoadSendData(Boundary, FileFullName, _
"Filename", FileShortName, _
"proid", "0", _
"hash", Hash, _
"uid", Uid, _
"title", Title, _
"filetype", Filetype, _
"Filedata", FileShortName, _
"Upload", "Submit Query")
'上传
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", "http://club.excelhome.net/misc.php?mod=swfupload&fid=2&action=swfupload&operation=upload", False
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
.Send SendData
Debug.Print .responsetext '出现一串数字则为成功。到论坛发帖的界面可看到“未使用的附件”的提示。
End With
End Sub
Function GetBoundary() As String
'生成Boundary
Dim i As Integer, r As Integer
Do While i < 30
r = Int(Rnd * 75 + 48)
If r < 58 Or (r > 64 And r < 91) Or r > 96 Then
GetBoundary = GetBoundary & Chr(r)
i = i + 1
End If
Loop
GetBoundary = String(10, "-") & GetBoundary
End Function
Function GetUpLoadSendData(Boundary As String, FileFullName As String, ParamArray NameValue()) As Byte()
'NameValue()必须成双,前一个是名称,后一个是值
'NameValue()最后一对是文件流之后的名称值对
'NameValue()倒数第二对是文件流信息相关的两个数据
Dim DataBefore, DataAfter
Dim arrBytData(1 To 3), bytData() As Byte
Dim i As Long, j As Long, n As Long
'连接文件流之前的各项名称值对
For i = 0 To UBound(NameValue) - 4 Step 2 '最后两对单独处理
DataBefore = DataBefore & "--" & Boundary & vbCrLf
DataBefore = DataBefore & "Content-Disposition: form-data; name=""" & NameValue(i) & """" & vbCrLf
DataBefore = DataBefore & vbCrLf
DataBefore = DataBefore & NameValue(i + 1) & vbCrLf
Next
'连接文件流此项的Content-Disposition
DataBefore = DataBefore & "--" & Boundary & vbCrLf
DataBefore = DataBefore & "Content-Disposition: form-data; name=""" & NameValue(i) & """; filename=""" & NameValue(i + 1) & """" & vbCrLf
DataBefore = DataBefore & "Content-Type: application/octet-stream" & vbCrLf
DataBefore = DataBefore & vbCrLf
'文件流前面的字符串转为流
arrBytData(1) = StrToUTF8Byte(DataBefore)
'文件转流
arrBytData(2) = FileToByte(FileFullName)
'文件流之后的字符串(一项)
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=""" & NameValue(i) & """" & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & NameValue(i + 1) & vbCrLf
DataAfter = DataAfter & "--" & Boundary & "--"
arrBytData(3) = StrToUTF8Byte(DataAfter) '转为流
'合并字符流和文件流
ReDim bytData(UBound(arrBytData(1)) + UBound(arrBytData(2)) + UBound(arrBytData(3)) + 2)
For i = 1 To 3
For j = 0 To UBound(arrBytData(i))
bytData(n) = arrBytData(i)(j)
n = n + 1
Next
Next
GetUpLoadSendData = bytData
End Function
Function StrToUTF8Byte(strText)
'文本转UTF-8编码并去除BOM头
With CreateObject("adodb.stream")
.Mode = 3 'adModeReadWrite
.Type = 2 'adTypeText
.Charset = "UTF-8"
.Open
.Writetext strText
.Position = 0
.Type = 1 'adTypeBinary
.Position = 3 '去除UTF-8编码文本前面的BOM头(三个字节)
StrToUTF8Byte = .Read()
.Close
End With
End Function
Function FileToByte(strFileName As String)
'文件转流
With CreateObject("Adodb.Stream")
.Open
.Type = 1 'adTypeBinary
.LoadFromFile strFileName
FileToByte = .Read
.Close
End With
End Function
--------------------------------------------------------------------------------------
该网站带了API对接,可是不知道怎么用,就在网站的左上角
新人第一次发帖,期待各位大佬的指点
下面是各位大佬可能会用到的自定义公式:
大部分还是从这个帖子复制的:
不懂html也来学网抓(xmlhttp/winhttp+fiddler)
http://club.excelhome.net/thread-1159783-1-1.html
(出处: ExcelHome技术论坛)
向前辈致敬
Function GetBoundary() As String
'生成Boundary
Dim I As Integer, r As Integer
Do While I < 16
r = Int(Rnd * 75 + 48)
If r < 58 Or (r > 64 And r < 91) Or r > 96 Then
GetBoundary = GetBoundary & Chr(r)
I = I + 1
End If
Loop
GetBoundary = String(4, "-") & "WebKitFormBoundary" & GetBoundary
End Function
Function GetUpLoadSendData(Boundary As String, filePath As String, Timestamp As String, Auth_token As String) As Byte()
Dim DataBefore, DataAfter
Dim arrBytData(1 To 3), bytData() As Byte
Dim I As Long, j As Long, n As Long
'文件流之前的字符串
DataBefore = DataBefore & "--" & Boundary & vbCrLf
DataBefore = DataBefore & "Content-Disposition: form-data; name=" & Chr(34) & "source" & Chr(34) & "; filename=" & Chr(34) & qqq & Chr(34) & vbCrLf
DataBefore = DataBefore & "Content-Type: image/jpeg" & vbCrLf
DataBefore = DataBefore & vbCrLf
'文件流前面的字符串转为流
arrBytData(1) = StrToUTF8Byte(DataBefore)
'文件转流
arrBytData(2) = FileToByte(filePath)
'文件流之后的字符串
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " type " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & "file" & vbCrLf
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " action " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & "upload" & vbCrLf
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " timestamp " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & Timestamp & vbCrLf
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " auth_token " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & Auth_token & vbCrLf
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " album_id " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & "6Jn83D" & vbCrLf
DataAfter = "--" & Boundary & vbCrLf
DataAfter = DataAfter & "Content-Disposition: form-data; name=" & Chr(34) & " expiration " & Chr(34) & vbCrLf
DataAfter = DataAfter & vbCrLf
DataAfter = DataAfter & "P1W" & vbCrLf
DataAfter = DataAfter & "--" & Boundary & "--"
arrBytData(3) = StrToUTF8Byte(DataAfter) '转为流
'合并字符流和文件流
ReDim bytData(UBound(arrBytData(1)) + UBound(arrBytData(2)) + UBound(arrBytData(3)) + 2)
For I = 1 To 3
For j = 0 To UBound(arrBytData(I))
bytData(n) = arrBytData(I)(j)
n = n + 1
Next
Next
GetUpLoadSendData = bytData
End Function
Function StrToUTF8Byte(strText)
'文本转UTF-8编码并去除BOM头
With CreateObject("adodb.stream")
.Mode = 3 'adModeReadWrite
.Type = 2 'adTypeText
.Charset = "UTF-8"
.Open
.Writetext strText
.Position = 0
.Type = 1 'adTypeBinary
.Position = 3 '去除UTF-8编码文本前面的BOM头(三个字节)
StrToUTF8Byte = .Read()
.Close
End With
End Function
Function FileToByte(strFileName As String)
'文件转流
With CreateObject("Adodb.Stream")
.Open
.Type = 1 'adTypeBinary
.LoadFromFile strFileName
FileToByte = .Read
.Close
End With
End Function
|
|