|
以下是我看了教程,爬的12306上海到北京的时刻表,供参考
Sub login12306()
Dim ss
With CreateObject("winhttp.winhttprequest.5.1")
.Open "GET", "https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2018-04-21&leftTicketDTO.from_station=SHH&leftTicketDTO.to_station=BJP&purpose_codes=ADULT", False
.setrequestheader "Referer", "https://kyfw.12306.cn/otn/leftTicket/init"
.setrequestheader "Cookie", "JSESSIONID=A5F10A1E313985CE650C5612569D9637; route=c5c62a339e7744272a54643b3be5bf64; BIGipServerotn=1691943178.24610.0000; current_captcha_type=C; _jc_save_fromStation=%u4E0A%u6D77%2CSHH; _jc_save_toStation=%u5317%u4EAC%2CBJP; _jc_save_fromDate=2018-04-21; _jc_save_toDate=2018-04-20; _jc_save_wfdc_flag=dc"
.send
ss = .responseText
MsgBox ss
Sheet3.Cells(1, 1) = ss
End With
End Sub
Sub reg12306()
Dim str, matc
Dim j, i
Dim regx As Object
j = 1
Set regx = CreateObject("vbscript.regexp")
str = Sheet3.Cells(1, 1)
Dim s
With regx
.Global = True
'.Pattern = "\""" & "1,\S+"
.Pattern = "预\S\|([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)\S([^|]*)"
'MsgBox "\{""pro\S+ \S+ \S+\""}"
Set matc = .Execute(str)
For Each s In matc
For i = 0 To s.SubMatches.Count - 1
Sheet3.Cells(j, i + 2) = s.SubMatches.Item(i)
Next i
j = j + 1
Next
End With
End Sub
|
|