level 10
hadstj
楼主
活动模式
#lightopen System;;
open System.IO;;
open System.Text;;
open System.Text.RegularExpressions;;
open System.Net;;
let url = @"http://www.xunread.com/article/b6f278f1-041b-4029-8fc7-fbb6d7c43fb8/index.shtml"
let downloadUrl (url:string) =
let req = HttpWebRequest.Create(url)
let rsp = req.GetResponse()
use rst = rsp.GetResponseStream()
use reader = new StreamReader( rst, Encoding.GetEncoding("GB2312") )
let str = reader.ReadToEnd()
str
let stream = downloadUrl url
let (|ParseRegex|_|) regex str =
let m = Regex(regex ).Match(str)
if m.Success
then Some (List.tail [ for x in m.Groups -> x.Value ])
else None
let (|ParseRegexes0|_|) regex str =
let m = Regex(regex).Matches(str)
if m.Count > 0
then Some ( [ for i in m ->
List.tail[ for j in i.Groups -> j.Value ]
] )
else None
let parseIds0 str =
match str with
| ParseRegexes0 @"<a href='([\d]+)\.([\w]+)'>" id -> id
| _ -> []
let Ids0 = stream |> parseIds0 |> Seq.map (fun [i; j] -> j + "." + i)
这种写法,怎么感觉没有下面方法看起来直观。
let (|ParseRegexes|_|) regex str =
let m = Regex(regex).Matches(str)
if m.Count > 0
then Some ([for x in m -> x.Groups.[1].Value])
else None
let parseIds1 str =
match str with
| ParseRegexes @"<a href='([\d]+\.[\w]+)'>" id -> id
| _ -> []
let parseIds2 str =
match str with
| ParseRegex @"([\d]+)\.([\w]+)" [id; s] -> s + "." + id
| _ -> ""
let Ids = stream |> parseIds1 |> Seq.map parseIds2
2013年02月04日 13点02分
1
#lightopen System;;
open System.IO;;
open System.Text;;
open System.Text.RegularExpressions;;
open System.Net;;
let url = @"http://www.xunread.com/article/b6f278f1-041b-4029-8fc7-fbb6d7c43fb8/index.shtml"
let downloadUrl (url:string) =
let req = HttpWebRequest.Create(url)
let rsp = req.GetResponse()
use rst = rsp.GetResponseStream()
use reader = new StreamReader( rst, Encoding.GetEncoding("GB2312") )
let str = reader.ReadToEnd()
str
let stream = downloadUrl url
let (|ParseRegex|_|) regex str =
let m = Regex(regex ).Match(str)
if m.Success
then Some (List.tail [ for x in m.Groups -> x.Value ])
else None
let (|ParseRegexes0|_|) regex str =
let m = Regex(regex).Matches(str)
if m.Count > 0
then Some ( [ for i in m ->
List.tail[ for j in i.Groups -> j.Value ]
] )
else None
let parseIds0 str =
match str with
| ParseRegexes0 @"<a href='([\d]+)\.([\w]+)'>" id -> id
| _ -> []
let Ids0 = stream |> parseIds0 |> Seq.map (fun [i; j] -> j + "." + i)
这种写法,怎么感觉没有下面方法看起来直观。
let (|ParseRegexes|_|) regex str =
let m = Regex(regex).Matches(str)
if m.Count > 0
then Some ([for x in m -> x.Groups.[1].Value])
else None
let parseIds1 str =
match str with
| ParseRegexes @"<a href='([\d]+\.[\w]+)'>" id -> id
| _ -> []
let parseIds2 str =
match str with
| ParseRegex @"([\d]+)\.([\w]+)" [id; s] -> s + "." + id
| _ -> ""
let Ids = stream |> parseIds1 |> Seq.map parseIds2