看板 Programming 關於我們 聯絡資訊
小弟最近在寫爬蟲 用的語言是Visual Basic。目前可以用httpWebRequest下載到一般網頁原始碼 但是對於有憑證要求的網頁,例如PTT八卦板網頁版,會要求使用者點選"已滿18歲", 就不知道要如何通過。 小弟的問題是,VB要怎麼寫WebRequest的POST? 參考過一些網友的寫法,以及MSDN,目前有的code Dim Req As Net.WebRequest Dim postData As String = "referer:https://www.ptt.cc/ask/over18?from=%2Fbbs%2FGossiping%2Findex.html" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) Req = Net.WebRequest.Create("https://www.ptt.cc/ask/over18") Req.Method = "POST" Req.ContentType = "application/x-www-form-urlencoded" Req.ContentLength = byteArray.Length Dim dataStream As Stream = Req.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() 這個POST沒有效果...... 希望大大不吝指教! 感謝~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 99.99.37.185 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1435000875.A.C9C.html
ofy: 用CookieContainer加一個over18=1 1.172.2.144 06/23 06:35
ofy: 或是用CookieContainer保存POST傳回的Cookies 1.172.2.144 06/23 06:40
ofy: 並在下次request時使用 1.172.2.144 06/23 06:41
ofy: 不會用Fiddler分析http header 1.172.2.144 06/23 06:59
ofy: 至少也要會用Browsers內建的F12功能 1.172.2.144 06/23 07:00