I have this to extract URL from google search result ( https://www.google.com/search?q=myquery&num=100 )
@"(?<=<h3 class=\""r\""><a href=\""\/url\?q=)(.*?)(?=&)";
Here's my code to extract URL from google search result
const string regexPattern = @"(?<=<h3 class=\""r\""><a href=\""\/url\?q=)(.*?)(?=&)";
public static string[] TopUrls(string data)
{
Regex regex = new Regex(regexPattern);
MatchCollection collection = regex.Matches(data);
return collection.Cast<Match>()
.Select(m => m.Value)
.ToArray();
}
string downloadUrl = "https://www.google.com" + "/search?q=" + keyword.ToString() + "&num=" + numResults + "&as_qdr=all&ei=LrUVVf7UMrPfsAS7lICgCw&sa=N&biw=1440&bih=690";
fetch.Headers.Set(HttpRequestHeader.Host, "www.google.com");
string data = fetch.DownloadString(downloadUrl);
string[] results = TopUrls(data);
from that code i can extract each URL from google search result.
Here's the result: https : //www blogger com/ profile/ 15582992268736301561 https : //www blogger com/ profile /17377873899922361640
How to write regex for this URL? http://www.bing.com/search?q=myquery&count=100
Thank You :)
试试这样的<h2>*?<a\\s+[^>]*?href="([^"]*)"
Why not use Bing Search API s? If you really must parse the HTML, you're looking for algo results. Get the li tags with b_algo class and extract the URL from them.
Your first step is to use:
<cite>(.*?)</cite>
Then you need another regex to remove <strong>
tags
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.