首页
讨论区
新职位
搜索论坛
什么's new
新职位
新的个人资料帖子
最新活动
会员
目前的访客
新的个人资料帖子
搜索个人资料帖子
VB.NET社区
登录
登记
什么's new
搜索
搜索
仅搜索标题
经过:
新职位
搜索论坛
Menu
Log in
Register
安装应用
安装
首页
讨论区
Visual Studio .NET
.NET Framework
搜寻价格(为什么总是出现错误!)
您正在使用过期的浏览器。它可能无法正确显示此网站或其他网站。
您应该升级或使用
替代浏览器
.
回复主题
信息
<blockquote data-quote="Noob_The_ Jacky" data-source="post: 20735" data-attributes="member: 13851"><p>To be clear of what you mean dynamically. Is that you mean the price would change without refreshing the page? No, I must press "F5" to refresh the price.</p><p>1. With using "webclient " get the link, I can't get through Xpath(seem to be I can't get anythings).</p><p>2. But when it come to using "HtmlWeb", it seem to go through all the process. Even though I still can't crawler the price , I able to reach some useless words(as attachment).</p><p>Here is the coding:</p><p>[CODE lang="csharp" title="HtmlWeb"]using System;</p><p>using HtmlAgilityPack;</p><p>namespace http</p><p>{</p><p> class Program</p><p> {</p><p> static void Main(string[] args)</p><p> {</p><p> HtmlWeb webClient = new HtmlWeb();</p><p> HtmlDocument doc = webClient.Load("http://www.aastocks.com/tc/stocks/market/bmpfutures.aspx?future=200300");</p><p> HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("/html/body/form/div[5]/div[1]/div[2]/div[2]"); </p><p> foreach (HtmlNode node in nodes)</p><p> {</p><p> Console.WriteLine(node.InnerText.Trim());</p><p> }</p><p> doc = null;</p><p> nodes = null;</p><p> webClient = null;</p><p> Console.WriteLine("Completed.");</p><p> Console.ReadLine();</p><p> } </p><p> }</p><p>}[/CODE]</p><p></p><p>[CODE lang="csharp" title="WebClient"]using System;</p><p>using System.Collections.Generic;</p><p>using System.Text;</p><p>using System.Net;</p><p>using System.IO;</p><p>using HtmlAgilityPack;</p><p></p><p>namespace http</p><p>{</p><p> class webcliclassl</p><p> {</p><p> public static void webgrab(string http) {</p><p></p><p> try</p><p> {</p><p> WebClient httpins = new WebClient();</p><p></p><p> httpins.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");</p><p> httpins.Headers.Add("Method", "GET"); </p><p> Stream resp = httpins.OpenRead(http);</p><p> StreamReader resstring = new StreamReader(resp);</p><p> string s = resstring.ReadToEnd();</p><p> HtmlDocument doc = new HtmlDocument();</p><p> doc.LoadHtml(http); // convert to doc</p><p> [1]/div[4]/div[5]/table/tbody/tr[1]/td[1]/div[4]</p><p> HtmlNodeCollection pricenode = doc.DocumentNode.SelectNodes("/html/body/form/div[4]/div[1]/div[4]/div[5]/table/tbody/tr[1]/td[1]/div[4]");</p><p> foreach (HtmlNode i in pricenode)</p><p> {</p><p> Console.WriteLine(i.InnerText.Trim());</p><p> }</p><p> resstring.Close();</p><p> }</p><p> catch (Exception e) {</p><p> Console.WriteLine(e.Message);</p><p> }</p><p> }</p><p> }</p><p>}[/CODE]</p><p></p><p>To be very honest, I am looking for someone can modify my coding since I have no idea how to deal with DOM.</p><p>Let me study your brilliant work and learn from your wisdom.</p><p></p><p></p><p>And a little remark:</p><p>It isn't that complex when I am using Python(I am not using xpath, I don't know how to name that method, see attachment).</p><p>Is that possible to using that method to local what I want in C#?</p></blockquote><p></p>
Insert quotes…
确认
发表回复
首页
讨论区
Visual Studio .NET
.NET Framework
搜寻价格(为什么总是出现错误!)
本网站使用Cookie来帮助个性化内容,调整您的体验并在注册时保持登录状态。
继续使用本网站,即表示您同意我们使用cookie。
接受
了解更多…
最佳
底部