Created
June 26, 2011 15:07
-
-
Save yangacer/1047685 to your computer and use it in GitHub Desktop.
Extract link from HTML using RE2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RE2 link("(?ims)(?:\\<a([^\\>]+)href=\\\")([^\\\"]+)\\\""); | |
| re2::StringPiece content(html_text); | |
| string match; | |
| string domain; | |
| while(RE2::FindAndConsume(&content, link, (void*)0, &match)){ | |
| if(match[0] == '/'){ | |
| if(!domain.size()){ | |
| evbuffer_add_printf(evb, "Domain name required.\n"); | |
| evhttp_send_reply(req, HTTP_BADREQUEST, "Client", evb); | |
| break; | |
| } | |
| match = domain + match; | |
| fprintf(stderr, "%s\n", match.c_str()); | |
| }else{ | |
| fprintf(stderr, "%s\n", match.c_str()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment