我在從網頁抓取資料時遇到問題,我得到了解決方案 從使用 iframe c#的網頁抓取資料
我的問題是他們更改了現在是https://webportal.thpa.gr/ctreport/container/track的網頁,我認為它沒有使用 iFrames,我無法取回任何資料。
有人可以告訴我是否可以使用相同的方法從該網頁獲取資料,還是應該使用不同的方法?
我不知道@coder_b 如何發現我應該使用https://portal.thpa.gr/fnet5/track/index.php作為網頁并且我應該使用
var reqUrlContent =
hc.PostAsync(url,
new StringContent($"d=1&containerCode={reference}&go=1", Encoding.UTF8,
"application/x-www-form-urlencoded"))
.Result;
傳遞變數
編輯:當我檢查網頁時,有一個包含數字的輸入
輸入型別="text" id="report_container_containerno" name="report_container[containerno]" required="required" minlength="11" maxlength="11" placeholder="E/K για αναζ?τηση" value="ARKU2215462" 我可以使用一些東西來傳遞 HtmlAgilityPack 然后它應該很容易閱讀結果
此外,當我檢查 DocumentNode 時,它??似乎向我顯示了我應該同意的 cookie 頁面。我可以繞過或自動允許 cookie 嗎?
uj5u.com熱心網友回復:
嘗試這個:
public static string Download(string search)
{
var request = (HttpWebRequest)WebRequest.Create("https://webportal.thpa.gr/ctreport/container/track");
var postData = string.Format("report_container[containerno]={0}&report_container[search]=", search);
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
using (var response = (HttpWebResponse)request.GetResponse())
using (var stream = new StreamReader(response.GetResponseStream()))
{
return stream.ReadToEnd();
}
}
用法:
var html = Download("ARKU2215462");
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483239.html
上一篇:'Viewpagesource'和document.querySelector("html").innerHTML之間的區別是什么?
