作者daviden (daviden)
看板Programming
标题[请益] PTT爬虫
时间Tue Jun 23 03:21:12 2015
小弟最近在写爬虫
用的语言是Visual Basic。目前可以用httpWebRequest下载到一般网页原始码
但是对於有凭证要求的网页,例如PTT八卦板网页版,会要求使用者点选"已满18岁",
就不知道要如何通过。
小弟的问题是,VB要怎麽写WebRequest的POST?
参考过一些网友的写法,以及MSDN,目前有的code
Dim Req As Net.WebRequest
Dim postData As String =
"referer:
https://webptt.com/cn.aspx?n=/ask/over18?from=%2Fbbs%2FGossiping%2Findex.html"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
Req = Net.WebRequest.Create("
https://webptt.com/cn.aspx?n=/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://webptt.com/cn.aspx?n=bbs/Programming/M.1435000875.A.C9C.html
1F:→ ofy: 用CookieContainer加一个over18=1 1.172.2.144 06/23 06:35
2F:→ ofy: 或是用CookieContainer保存POST传回的Cookies 1.172.2.144 06/23 06:40
3F:→ ofy: 并在下次request时使用 1.172.2.144 06/23 06:41
4F:→ ofy: 不会用Fiddler分析http header 1.172.2.144 06/23 06:59
5F:→ ofy: 至少也要会用Browsers内建的F12功能 1.172.2.144 06/23 07:00