Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OLX_Scraper
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string getwebsitecontent(string url)
- {
- string html = String.Empty;
- WebRequest request = WebRequest.Create(url);
- WebResponse response = request.GetResponse();
- Stream data = response.GetResponseStream();
- using (StreamReader sr = new StreamReader(data))
- {
- html = sr.ReadToEnd();
- }
- return html+"hjhgjhgjh";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- bg.CancelAsync();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- }
- BackgroundWorker bg = new BackgroundWorker();
- private void button3_Click(object sender, EventArgs e)
- {
- for (int pages = 1; pages <= numericUpDown1.Value; pages++)
- {
- string url = "https://www.olx.com.pk/mobile-phones/?page=" + pages;
- var links = Regex.Matches(getwebsitecontent(url).ToString(), "<a href=\"([^<]*)\" class=\"marginright5 link linkWithHash detailsLink\">");
- foreach (Match match in links)
- {
- richTextBox1.Text += match.Groups[1].Value + "\n";
- }
- var location = Regex.Matches(getwebsitecontent(url).ToString(), "<span>([^<]*)</span> </small>");
- foreach (Match match in location)
- {
- richTextBox2.Text += match.Groups[1].Value + "\n";
- }
- var price = Regex.Matches(getwebsitecontent(url).ToString(), "<strong class=\"c000\">([^<]*)</strong>");
- foreach (Match match in price)
- {
- richTextBox3.Text += match.Groups[1].Value.Trim().Trim().Trim().Trim().Trim().Trim() + '\n';
- }
- var time = Regex.Matches(getwebsitecontent(url).ToString(), "<p class=\"color-9 lheight14 margintop3 small\">([^<]*)</p>");
- foreach (Match match in time)
- {
- richTextBox4.Text += match.Groups[1].Value + "\n";
- }
- char delimiterChars = '\n';
- string[] linker = richTextBox1.Text.Split(delimiterChars);
- string[] locationer = richTextBox2.Text.Split(delimiterChars);
- string[] pricer = richTextBox3.Text.Split(delimiterChars);
- string[] eimerx = richTextBox4.Text.Split(delimiterChars);
- progressBar1.Maximum = linker.Length - 1;
- for (int i = 0; i < linker.Length - 1; i++)
- {
- if (i == 0) { i++; }
- progressBar1.Value = i;
- this.dataGridView1.Rows.Add(i, linker[i], locationer[i], pricer[i], eimerx[i]);
- }
- }
- }
- //5d329
- private void button6_Click(object sender, EventArgs e)
- {
- char delimiterChars = '\n';
- string[] urlz = richTextBox5.Text.Split(delimiterChars);
- for (int i = 0; i < urlz.Length - 1; i++)
- {
- richTextBox6.Text += getwebsitecontent(urlz[i].ToString().Trim('\n'));
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment