我已经读过HTMLAgility 1.4是一个很好的解压缩网页的解决方案.作为一名新程序员,我希望我能对这个项目有所了解.我这样做是作为ac#申请表.我正在使用的页面非常简单.我需要的信息只停留在2个标签之间.我的目标是将Part-Num,Manu-Number,Description,Manu-Country,Last Modified,Last Modified By的数据拉出页面并将数据发送到sql表.一个转折是还有一个小的png pic,也需要从src ="/ partcode/number中获取.
我没有任何已完成的代码.我以为这段代码会告诉我我是否正朝着正确的方向前进.即使进入调试我也看不到它做了什么.有人可能会指出我在这方面的正确方向.越详细越好,因为很明显我需要学习很多东西.谢谢,我真的很感激.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using System.Xml;
namespace Stats
{
class PartParser
{
static void Main(string[] args)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("http://localhost");//my understanding this reads the entire page in?
var tables = doc.DocumentNode.SelectNodes("//table");// I assume that this sets up the search for words containing table
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
Console.ReadKey();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
网络代码是:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 …Run Code Online (Sandbox Code Playgroud) 我是c的新手#我必须先提问才能开始!
我想要做的是在文本框中输入一个数字,将其发送到附加的sql compact数据库,检查数字是否在表中,如果为true则将数据返回到表单.如果为false,我想运行一些代码来获取信息并更新表,添加到表中,发送到表单.除了通过C#创建sql表之外,有人可以帮助我对这个概念进行原型设计,所以我可以开始阅读这些概念,以便我可以开始构建我项目的这一部分吗?谢谢.
为了学习最佳实践,我有一个问题.在找到周日开始的方法时,我遇到了这个帖子."http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week"
问题:我需要4-3-2011的格式:有没有更有效的方法来实现这一点,而不是我的代码黑客攻击?
DateTime dt = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
int ddt = dt.Day;
int mdt = dt.Month;
int ydt = dt.Year;
string sddt = ddt.ToString();
string smdt = mdt.ToString();
string sydt = ydt.ToString();
string fdate = (smdt + "-" + sddt + "-" + sydt);
Run Code Online (Sandbox Code Playgroud)
线程代码:作者Sarcastic
public static class DateTimeExtensions
{
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = dt.DayOfWeek - startOfWeek;
if (diff < 0)
{
diff += 7;
}
return dt.AddDays(-1 * diff).Date;
}
DateTime dt …Run Code Online (Sandbox Code Playgroud) 我尝试了几种组合但没有成功.该数据的完整xpath是.//*[@id='detail_row_seek_37878']/td 问题是每个节点的数字部分'37878'发生了变化,因此我无法使用foreach循环遍历节点.有没有办法使用通配符并减少xpath .//*[@id='detail wildcard,以绕过绝对值部分?我正在使用html敏捷包.
HtmlNode ddate = node.SelectSingleNode(".//*[@id='detail_row_seek_37878']/td");
Run Code Online (Sandbox Code Playgroud) 作为编程新手,我阅读了大量的示例代码并尝试将各种东西混合在一起以试图了解哪些有用.我正在使用html agility pack试图废弃新闻网页.
问题:我测试的其中一个节点不使用静态值,它使用查看时间.如何将此应用于switch {case}方法.如果我在整个方法中偏离基础,我也愿意接受任何建议.
另请注意:我不需要捕获此节点,如果有一种方法可以跳过它对我有用.
我决定使用一个使用开关的exapmle,
var rows = doc.DocumentNode.SelectNodes(".//*[@id='weekdays']/tr");
foreach (var row in rows)
{
var cells = row.SelectNodes("./td");
string title = cells[0].InnerText;
var valueRow = cells[2];
switch (title)
{
case "Date":
HtmlNode date = valueRow.SelectSingleNode("//*[starts-with(@id, 'detail_row_seek')]/td");
Console.WriteLine("UPC=A:\t" + date.InnerText);
break;
case "":
string Time = valueRow.InnerText;
Console.WriteLine("Time:\t" + Time);
break;
case "News":
string Time = valueRow.InnerText;
Console.WriteLine("News:\t" + News);
break;
}
Run Code Online (Sandbox Code Playgroud)
摘录html
<table id="weekdays" cellpadding="6" cellspacing="0" border="0" width="100%">
<tr>
<td class="thead" style="border-bottom: 1px solid #d1d1e1;font-weight:normal; text-align: center; …Run Code Online (Sandbox Code Playgroud) 我正在处理的项目涉及数据库和数据源的Web服务.这个问题,我有几个,是基于这样的想法:如果我输入一个产品编号textBox1,我想看看数字是否已经存在于数据库中,如果不是,我想让它运行我编写的代码Web服务并抓取数据然后更新数据库.
我应该使用什么代码来检查Product_ID是空还是空
我需要编写什么代码,以便如果Product_ID为null或为空,它将调用我已编写的代码从Web服务中获取数据?
我的linq代码是:
Test_Data_ClassDataContext db = new Test_Data_ClassDataContext();
var q = from p in db.Product_Masters
where p.Product_ID.Equals(textBox1.Text)
select p;
Run Code Online (Sandbox Code Playgroud)
窃取他人的想法我试图测试null如果null运行Web服务代码,如果不是null将其发送到datagridview进行显示.
If (q == null)
{
Somehow call the other code so it takes textBox1 and get the data from the service
}
else
{
dataGridView1.DataSource = q;
}
Run Code Online (Sandbox Code Playgroud)
背景:我是c#的新手,曾经和vb6一起玩过,所以对我而言,c#不仅仅是学习一门新语言而且还学会再次走路,更不用说我从来都不是一个优秀的vb6程序员.
c# ×6
.net ×4
html-parsing ×2
data-mining ×1
database ×1
linq-to-sql ×1
sql ×1
web-scraping ×1
xpath ×1