日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

读淘宝页面字节流提取宝贝图片地址宝贝标题宝贝价格

發布時間:2023/12/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 读淘宝页面字节流提取宝贝图片地址宝贝标题宝贝价格 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public static class taobao_message
??????? {
??????????? /// <summary>
??????????? /// 讀頁面的byte轉化為string
??????????? /// </summary>
??????????? /// <param name="url">地址</param>
??????????? /// <returns></returns>
??????????? public static string webclinet_content(string url)
??????????? {
??????????????? url = url.Replace("http://", "");
??????????????? System.Net.WebClient client = new WebClient();
??????????????? byte[] page = client.DownloadData("http://" + url); ?
??????????????? string content = System.Text.Encoding.GetEncoding("GB2312").GetString(page);//淘寶的頁面編碼為gb2312
??????????????? return content;
??????????? }
??????????? /// <summary>
??????????? /// 讀淘寶寶貝的信息
??????????? /// 數組內容{寶貝圖片地址,寶貝標題,寶貝價格}
??????????? /// </summary>
??????????? /// <param name="url">寶貝地址</param>
??????????? /// <returns></returns>
??????????? public static string[] baobei_mess(string url)
??????????? {
??????????????? string content = webclinet_content(url);
??????????????? string baobei_img =get_taobao(content,1);
??????????????? string baobei_title = get_taobao(content,2);
??????????????? string baobei_price = get_taobao(content,3);
??????????????? string[] arry1 = {baobei_img,baobei_title,baobei_price};
??????????????? return arry1;;
??????????? }
??????????? /// <summary>
??????????? /// 特定標簽內容提取
??????????? /// </summary>
??????????? /// <param name="content">提取的字符串</param>
??????????? /// <param name="type">驗證類型0:空; 1:淘寶貝圖片;2:寶貝標題;3:寶貝價格;</param>
??????????? /// <returns></returns>
??????????? public static string get_taobao(string content, int type)
??????????? {
??????????????? string result = "";
??????????????? string reg = "";
??????????????? switch (type)
??????????????? {
??????????????????? case 0: return "";
??????????????????? case 1: reg = @"J_ImgBooth\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>"; break;
??????????????????? case 2: reg = "<h3>(<a[^>]*>)?([^<]*)(</a>)?</h3>"; break;
??????????????????? case 3: reg = "J_StrPrice[^>]*>([^<>]*)(</)"; break;
??????????????? }
??????????????? string regex = reg;
??????????????? Regex re = new Regex(regex);
??????????????? MatchCollection matches = re.Matches(content);
??????????????? System.Collections.IEnumerator enu = matches.GetEnumerator();
??????????????? switch (type)
??????????????? {
??????????????????? case 0: return "";
??????????????????? case 1:
??????????????????????? while (enu.MoveNext() && enu.Current != null)
??????????????????????? {
??????????????????????????? Match match = (Match)(enu.Current);
??????????????????????????? result += match.Groups["imgUrl"];
??????????????????????? } break;
??????????????????? case 2:
??????????????????????? while (enu.MoveNext() && enu.Current != null)
??????????????????????? {
??????????????????????????? Match match = (Match)(enu.Current);
??????????????????????????? result += match.Groups[2];
??????????????????????? } break;
??????????????????? case 3:
??????????????????????? while (enu.MoveNext() && enu.Current != null)
??????????????????????? {
??????????????????????????? Match match = (Match)(enu.Current);
??????????????????????????? result += match.Groups[1];
??????????????????????? } break;
??????????????? }
??????????????? return result;
?????????? }
??????? }

總結

以上是生活随笔為你收集整理的读淘宝页面字节流提取宝贝图片地址宝贝标题宝贝价格的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。