3-12 搜索bookbao8
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using Book.Core;
using Book.Core.Model;
namespace Book.BookBao8
{
public class BookBao8DataProvider : DataProvider
{
public override Article GetArticle(IndexItem indexItem)
{
throw new NotImplementedException();
}
public override List<IndexItem> GetIndex(Story story)
{
throw new NotImplementedException();
}
public override List<Story> Search(string keyword)
{
var url = "https://www.bookbao8.com/Search/q_" + HttpUtility.UrlEncode( keyword);
var html= RequestHtml(url);
var ulstr = CutString(html, "<div class=\"search_box\"><ul>", "</ul>", true);
List<Story> list = new List<Story>();
MatchCollection matches =MatchTag(ulstr, "li");
foreach (Match item in matches)
{
var listr= item.Value;
Story story = new Story();
story.Title = GetText( CutString(listr,"<span class=\"t\">", "</a>", true));
story.WordNumber = CutString(listr, "大小:<span class=\"num\">", "</span>", true);
story.Author = CutString(listr, "作者:<span>", "</span>", true);
story.ImgSrc = GetTagAttribute(listr, "img", "src");
if (story.ImgSrc.StartsWith("/"))
{
story.ImgSrc = "https://www.bookbao8.com" + story.ImgSrc;
}
story.Url = "https://www.bookbao8.com"+GetTagAttribute(listr, "a", "href");
list.Add(story);
}
return list;
}
}
}