时间:2019-03-17 标签:c#htmlagilitypack
我们正在将一个电子商务网站迁移到一个新平台,因为他们的所有页面都是静态 html,并且他们的数据库中没有所有产品信息,所以我们必须抓取他们当前的网站以获取产品描述。
这是其中一页: http://www.cabinplace.com/accrugsbathblackbear.htm
什么最好的方法是将描述放入字符串中吗?我应该使用 html 敏捷包吗?如果是这样,该怎么做?因为我一般对 html Agility Pack 和 xhtml 很陌生。
谢谢
We are moving an e-commerce website to a new platform and because all of their pages are static html and they do not have all their product information in a database, we must scrape their current website for the product descriptions.
Here is one of the pages: http://www.cabinplace.com/accrugsbathblackbear.htm
What is the best was to get the description into a string? Should I use html agility pack? and if so how would this be done? as I am new to html agility pack and xhtml in general.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML Agility Pack 是用于此类工作的一个很好的库。
您没有指出是否所有内容都是这样构造的,也没有指出您是否已经从 HTML 文件中获得了您发布的那种片段,因此很难提供进一步的建议。
一般来说,如果所有页面的结构相似,我将使用 XPath 表达式来提取段落并从每个页面中选择
innerHtml
或innerText
。像下面这样:
The HTML Agility Pack is a good library to use for this kind of work.
You did not indicate if all of the content is structured this way nor if you have already gotten the kind of fragment you posted from the HTML files, so it is difficult to advise further.
In general, if all pages are structured similarly, I would use an XPath expression to extract the paragraph and pick the
innerHtml
orinnerText
from each page.Something like the following:
另外,
如果您需要一个好的工具来测试或查找 HAP 的 Xpath,您可以使用这个:
HTML-Agility-xpath-finder。它是使用相同的库制作的,因此如果您在此工具中找到 xpath,您就可以安全地在代码中使用。
Also,
If you need a good tool for testing or finding the Xpath for the HAP you can use this one:
HTML-Agility-xpath-finder. It is made using the same library so if you find a xpath in this tool you be securely able to use in your code.