سلام،
byte[] ResultsBuffer = new byte[16384]; string txtres;
string sfg = "خرید بلیط";
txtres = sfg.Replace(" ", "+");
//view-source:https://www.google.com/search?client...UTF-8&oe=UTF-8
string SearchResults = "http://google.com/search?client=opera&rls=x64&q=" + txtres + "&sourceid=opera&ie=UTF-8&oe=UTF-8";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SearchResults);
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
request.Referer = "https://www.google.com/";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.71";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(ResultsBuffer, 0, ResultsBuffer.Length);
if (count != 0)
{
tempString = Encoding.UTF8.GetString(ResultsBuffer, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
string sbb = sb.ToString();
var regex = new Regex(@"href=['""]([^ '""]+?)['""]", RegexOptions.IgnoreCase);
var urlList = regex.Matches(sbb);
foreach (Match item in urlList)
{
var val = item.Groups[1].Value;
if (!val.ToLower().Contains("google.com") &&
val.ToLower().Contains("http")
// خط مورد نیازت
&& val.ToLower().Contains("googleadservices.com/pagead"))
{
var url = val.Substring(val.LastIndexOf("http"));
lbshow.Items.Add(url);
}
}