d语言-下载网页,经过正则抓取对应的数据


---个人博客http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow mehtml

std.net.curlcurl

d语言的网路curl库,提供更高级的服务。post

依赖 libcurl。[std.net.curl模块详细介绍地址](https://dlang.org/phobos/std_net_curl.html)url

依赖于对libcurl的封装,提供一系列的高级方法哦。spa

download  upload  get  post  put  del  options  trace  connect  byLine  byChunk  byLineAsync  byChunkAsync .net


咱们这里用到了getcode

std.regexorm

d语言的正则库htm

match matchAll等blog


std.conv 

可使用!to(xxx)方法 用于类型转换

代码以下

import std.net.curl, std.stdio;
import std.regex;
import std.conv;

void main() {
    //fech data
    auto url = "http://novel.hongxiu.com/a/263958/";
    auto content = cast(string) get(url);
    //regex data
    auto  r = regex(r"http://w.hongxiu.com/(\d+)/index.html");  
    auto match_arr = matchFirst(content,r);
    int s_bid = 0;
    if(!match_arr.empty){
        auto s_b = match_arr[1];
        s_bid = to!int(s_b);
    }   
    writeln(s_bid);
}
相关文章
相关标签/搜索