Advertisement
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.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Net;
- namespace Natura_pojedynczy_produkt
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string id, fotoURL, marka, seria, nazwa, sku, pojemnosc, zawartosc, opis, ilosc;
- string RegularPrice, OldPrice, SpecialPrice;
- static DateTime aktualizacja = DateTime.Now.Date;
- String a = Convert.ToString(aktualizacja);
- private void button1_Click(object sender, EventArgs e)
- {
- label2.Text = "Aktualizacja: " + a;
- string url = textBox1.Text;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream());
- richTextBox1.Text = sr.ReadToEnd();
- sr.Close();
- string gotowyTekst = richTextBox1.Text;
- string[] daneStart = { "catalog_product/view/id/", "data-image=", "brand-name\">", "series-name\">", "itemprop=\"name\">", "product-sku\">"};
- string[] daneFinish = { "/", "\"", "</h2>", "</h3>", "</h1>", "</h3>"};
- string[] dane = { id, fotoURL, marka, seria, nazwa, sku };
- int znacznik = gotowyTekst.IndexOf("</html>") - gotowyTekst.IndexOf("customer-reviews");
- string skrocony = gotowyTekst.Remove(gotowyTekst.IndexOf("customer-reviews"), znacznik);
- string wyciety = skrocony;
- wyciety = wyciety.Replace("<div>", null);
- wyciety = wyciety.Replace("<span>", null);
- wyciety = wyciety.Replace("<br />", null);
- StreamWriter sw = new StreamWriter("wyciety_test.txt");
- sw.WriteLine(wyciety);
- sw.Close();
- StreamWriter lista = new StreamWriter("lista_test.txt");
- string daneJeden = wyciety;
- for (int i = 0; i < 6; i++)
- {
- daneJeden = daneJeden.Remove(0, daneJeden.IndexOf(daneStart[i]) + daneStart[i].Length);
- int pTo = daneJeden.IndexOf(daneFinish[i]);
- dane[i] = daneJeden.Substring(0, pTo).Trim();
- lista.Write(dane[i] + "\t");
- }
- string daneDwa = wyciety;
- daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("Pojemność</span>") + "Pojemność</span>".Length).Trim();
- int pTo1 = daneDwa.IndexOf("</span>");
- pojemnosc = daneDwa.Substring(0, pTo1).Trim();
- daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("Zawartość</span>") + "Zawartość</span>".Length).Trim();
- int pTo3 = daneDwa.IndexOf("</span>");
- zawartosc = daneDwa.Substring(0, pTo3).Trim();
- if (pojemnosc == zawartosc && pojemnosc != null)
- {
- ilosc = pojemnosc;
- zawartosc = null;
- }
- else
- {
- ilosc = zawartosc;
- }
- lista.Write(ilosc + "\t");
- lista.Close();
- StreamReader test = new StreamReader("lista_test.txt");
- richTextBox3.Text = test.ReadLine();
- test.Close();
- //if (obciety.Contains("old-price"))
- //{
- // obciety = obciety.Remove(0, obciety.IndexOf("class=\"price\">") + "class=\"price\">".Length).Trim();
- // int pTo2 = obciety.IndexOf("</span>");
- // label10.Text = "Cena przed promocją: " + obciety.Substring(0, pTo2).Trim();
- // label7.Text = "";
- // obciety = obciety.Remove(0, obciety.IndexOf("class=\"price\" itemprop=\"price\">") + "class=\"price\" itemprop=\"price\">".Length).Trim();
- // //int pTo2 = obciety.IndexOf("</span>");
- // label11.Text = "Cena promocyjna: " + obciety.Substring(0, pTo2).Trim();
- //}
- daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("description\">\n") + "description\">\n".Length).Trim();
- int pTo2 = daneDwa.IndexOf("</p>");
- opis = daneDwa.Substring(0, pTo2).Trim();
- StreamWriter tabelaOpisow = new StreamWriter("tabela_opisow.txt");
- tabelaOpisow.WriteLine(sku + "\t" + opis);
- tabelaOpisow.Close();
- richTextBox2.Text = opis;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void richTextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement