use b struct weblink: cstr href cstr title cstr desc def google(q) google(q, 10) def google(q, n) google.(q, n, 0) def google(q, n, start) google_alloc(q, n, start) vec *google_alloc(cstr q, int n, int start): New(v, vec, weblink, n) google(v, q, n, start) return v google(vec *v, cstr q, int n, int start): #http_debug = 1 # http_fake_browser(1) cstr query = url_encode(q) cstr fmt = "http://www.google.com/search?name=f&hl=en&num=%d&start=%d&nfpr=1&q=%s" cstr url = Format(fmt, n, start, query) Free(query) new(b, buffer, 1024) http_get(url, b) Free(url) # warn("%s", buffer_nul_terminate(b)) decl(cb, circbuf) buffer_to_circbuf(cb, b) new(b_split, circbuf, 1024) cb_io(cb, b_split) html_split() # buffer_free(b) # circbuf_to_buffer(b, b_split) cb_in(b_split) Eachline(s) if cstr_begins_with(s, "") && buflen(title)) break if s[0] != '<' print(s) b_out(desc) repeat s = rl() if !s || cstr_eq(s, "") || cstr_eq(s, "") || cstr_eq(s, "") break if s[0] != '<' && strcmp(s, "Cached") && strcmp(s, "Similar") && strcmp(s, " - ") s = cstr_space_trim(s) pf("%s ", s) if cstr_eq(s, "...") break vec_push(v, (weblink){ .href = strdup(href), .title = buffer_to_cstr(title), .desc = buffer_to_cstr(desc) }) circbuf_free(b_split) # TODO don't do this, use meta (when it works!) say_weblinks(vec *v): for_vec(i, v, weblink) if i->href: sf("url:\t%s", i->href) if i->title: sf("title:\t%s", i->title) if i->desc: sf("desc:\t%s", i->desc) sf() # if !strstr(i->href, ".cpan.") # sf() # continue # # i->html = http_get(i->href) # i->text = html2text(i->html) # cstr_dos_to_unix(i->text) # # say("text:") # # decl(b_text, buffer) # buffer_from_cstr(b_text, i->text) # b_in(b_text) # Eachline(s) # sf("\t%s", s) # # say() # # say("html:") # # decl(b_html, buffer) # buffer_from_cstr(b_html, i->html) # b_in(b_html) # Eachline(s) # sf("\t%s", s) # # say()