删除 RichTextBox 中符合条件的行
使用此链接 http://www.yellowpages.ca/search/?stype=si&what=sh&where=Ottawa,+ON&x=0&y=0 并告诉 HtmlAgilityPack 检索地址和地名同时(“//span[@class='listingTitle']|//div[@class='address']/text()[normalize-space(.)]”),我可以获得一个列表Richtextbox 中的地名和地址如下所示:
- jh ryder Machinery Limited
- permanent storage ltd 3344rideau
- rd, gloucester, on, k1g3n4
- kitchen Interiors 146 colonnade rd,
- nepean, on, k2e7y1
第一行是错误的,它没有地址。 2号线和4号线都很好,有地址。所以我能做的是:
检查每一行,
如果下一行不包含“numbers + ON”,则删除该行。
这将为我留下地名,后跟地址,然后我将每隔一行将其拆分为一个新的文本框(因此我有一个包含地名的文本框,另一个包含地址)。
我希望我说清楚了。
-DD,
Using this link http://www.yellowpages.ca/search/?stype=si&what=sh&where=Ottawa,+ON&x=0&y=0 and telling HtmlAgilityPack to retrieve both address and place name at the same time ("//span[@class='listingTitle']|//div[@class='address']/text()[normalize-space(.)]"), I can get a list of placenames and addresses like this in a richtextbox:
- jh ryder machinery limited
- convenience storage ltd 3344 rideau
- rd, gloucester, on, k1g3n4
- kitchen interiors 146 colonnade rd,
- nepean, on, k2e7y1
The first line is bad, it doesnt have an address. Line 2 and 4 are good, they have addresses. So what I could do is:
Check each line,
if the following line doesnt contain "numbers + ON" then delete line.
This will leave me with PlaceNames followed by addresses, which I will then split every other line into a new textbox, (so I have one textbox with placenames, and another with addresses).
I hope I made myself clear.
-Dd,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您还可以在 Xpath 中添加一个条件来检查文本“
ON,
”是否存在。因此,该列表是预先过滤的。I think you could also add a condition in the Xpath to check if text "
ON,
" is there. So, the list is pre-filtered.