正则表达式
<a href="bookDetail?bid=549843" style="margin-left:5px" target="_blank"红色是要匹配到的部分;蓝色是所有位置都有这个状态标志,即常量特征。
求正则表达式 正则表达式 --------------------编程问答-------------------- \<a\shref\=\"bookDetail\?bid\=\d+\"\sstyle\=\"margin\-left:5px\"\starget\=\"_blank\" --------------------编程问答-------------------- 这句怎么用?? --------------------编程问答--------------------
Regex reg=new Regex(@"(?i)(?<=<a\b[^>]*?href="")[^""]*?(?=style=""margin-left:\d+px"" target=""_blank"")");--------------------编程问答--------------------
foreach(Match m in reg.Matches(yourstr))
{
//m.Value就是你想要的
}
Regex reg=new Regex(@"(?i)(?<=<a\b[^>]*?href="")[^""]*?(?=" style=""margin-left:\d+px"" target=""_blank"")");--------------------编程问答-------------------- 囧~~
foreach(Match m in reg.Matches(yourstr))
{
//m.Value就是你想要的
}
Regex reg=new Regex(@"(?i)(?<=<a\b[^>]*?href="")[^""]*?(?="" style=""margin-left:\d+px"" target=""_blank"")");--------------------编程问答-------------------- 匹配不到啊。有点问题。 --------------------编程问答-------------------- 最后的一个可以。我再测试下。 --------------------编程问答-------------------- 用上个帖子我给你的HtmlAgilityPack下载地址 去下载dll
foreach(Match m in reg.Matches(yourstr))
{
//m.Value就是你想要的
}
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;
namespace HtmlAgilityDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
HtmlWeb htmlWeb = new HtmlWeb();
htmlWeb.OverrideEncoding = Encoding.UTF8;
HtmlAgilityPack.HtmlDocument htmlDoc = htmlWeb.Load(this.textBox2.Text);
HtmlAgilityPack.HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(@"//div[@class='book_tu']/ul");
foreach (HtmlNode anchor in anchors)
{
var href= anchor.SelectSingleNode(@"//li[@class='book_bg']//a[@style='margin-left:5px']").GetAttributeValue("href", "");
this.textBox1.Text += href + "\r\n";
}
}
}
} --------------------编程问答--------------------
HtmlNode node = anchor.SelectSingleNode(@"li[@class='book_bg']//a[@style='margin-left:5px']");上面那句写错了 那个dll下载地址http://htmlagilitypack.codeplex.com/releases/view/90925
你学过xpath入手会很快 --------------------编程问答--------------------
用你给出的数据测试没有问题啊 --------------------编程问答--------------------
http://download.csdn.net/detail/zhuankeshumo/5865413写的demo 你用这个比较好
--------------------编程问答-------------------- 路过学习的,呵呵 --------------------编程问答-------------------- 给你一个最简单的,
href=\"([^\"]+)\"
看看正则表达式关键字
补充:.NET技术 , C#