Public
Class
Form1
Private
Sub
DownText(strUrl
As
String
)
Dim
csStopwatch
As
New
Stopwatch
strUrl = GetHttpResutl(strUrl)
Dim
strPattern
As
String
=
"id=(.*?)&type="
Dim
match
As
Match = Regex.Match(strUrl, strPattern)
If
(match.Success)
Then
Dim
strID
As
String
= match.Groups(0).Value.Replace(
"id="
,
""
).Replace(
"&type="
,
""
)
strUrl = $
"http://note.youdao.com/yws/public/note/{strID}?editorType=0&cstk=cGtjFpHb"
Dim
jsonResult
As
String
= GetHttpResutl(strUrl,
False
)
Dim
csRootobject
As
Rootobject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Rootobject)(jsonResult)
Dim
strP
As
String
= csRootobject.p.Replace(
"/"
,
""
)
TextBox2.Text = $
"http://note.youdao.com/yws/api/personal/file/{strP}?method=download&inline=true&shareKey={strID}"
Else
MsgBox(
"分享链接无法解析"
, MsgBoxStyle.OkOnly,
"提示"
)
End
If
csStopwatch.
Stop
()
End
Sub
Private
Function
GetHttpResutl(strUrl
As
String
,
Optional
ByVal
bolUrl
As
Boolean
=
True
)
As
String
Using httpClient
As
New
HttpClient()
Try
Dim
response
As
HttpResponseMessage = httpClient.GetAsync(strUrl).Result
response.EnsureSuccessStatusCode()
If
bolUrl
Then
Return
response.RequestMessage.RequestUri.ToString
Else
Return
response.Content.ReadAsStringAsync().Result
End
If
Catch
ex
As
HttpRequestException
MsgBox($
"发生 HTTP 请求错误: {ex.Message}"
, MsgBoxStyle.OkOnly,
"提示"
)
Return
""
End
Try
End
Using
End
Function
Private
Sub
Btn_JX_Click(sender
As
Object
, e
As
EventArgs)
Handles
Btn_JX.Click
TextBox2.Text =
String
.Empty
DownText(txt_Url.Text)
End
Sub
End
Class
Public
Class
Rootobject
Public
Property
p
As
String
Public
Property
ct
As
Integer
Public
Property
su
As
Object
Public
Property
pr
As
Integer
Public
Property
au
As
Object
Public
Property
pv
As
Integer
Public
Property
mt
As
Integer
Public
Property
sz
As
Integer
Public
Property
domain
As
Integer
Public
Property
tl
As
String
Public
Property
isFinanceNote
As
Boolean
End
Class