Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Net;
  12.  
  13. namespace Natura_pojedynczy_produkt
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. string id, fotoURL, marka, seria, nazwa, sku, pojemnosc, zawartosc, opis, ilosc;
  23. string RegularPrice, OldPrice, SpecialPrice;
  24. static DateTime aktualizacja = DateTime.Now.Date;
  25.  
  26. String a = Convert.ToString(aktualizacja);
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. label2.Text = "Aktualizacja: " + a;
  31. string url = textBox1.Text;
  32. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  33. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  34. StreamReader sr = new StreamReader(response.GetResponseStream());
  35. richTextBox1.Text = sr.ReadToEnd();
  36. sr.Close();
  37. string gotowyTekst = richTextBox1.Text;
  38.  
  39. string[] daneStart = { "catalog_product/view/id/", "data-image=", "brand-name\">", "series-name\">", "itemprop=\"name\">", "product-sku\">"};
  40. string[] daneFinish = { "/", "\"", "</h2>", "</h3>", "</h1>", "</h3>"};
  41. string[] dane = { id, fotoURL, marka, seria, nazwa, sku };
  42. int znacznik = gotowyTekst.IndexOf("</html>") - gotowyTekst.IndexOf("customer-reviews");
  43. string skrocony = gotowyTekst.Remove(gotowyTekst.IndexOf("customer-reviews"), znacznik);
  44. string wyciety = skrocony;
  45. wyciety = wyciety.Replace("<div>", null);
  46. wyciety = wyciety.Replace("<span>", null);
  47. wyciety = wyciety.Replace("<br />", null);
  48. StreamWriter sw = new StreamWriter("wyciety_test.txt");
  49. sw.WriteLine(wyciety);
  50. sw.Close();
  51. StreamWriter lista = new StreamWriter("lista_test.txt");
  52. string daneJeden = wyciety;
  53.  
  54. for (int i = 0; i < 6; i++)
  55. {
  56. daneJeden = daneJeden.Remove(0, daneJeden.IndexOf(daneStart[i]) + daneStart[i].Length);
  57. int pTo = daneJeden.IndexOf(daneFinish[i]);
  58. dane[i] = daneJeden.Substring(0, pTo).Trim();
  59. lista.Write(dane[i] + "\t");
  60. }
  61. string daneDwa = wyciety;
  62. daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("Pojemność</span>") + "Pojemność</span>".Length).Trim();
  63. int pTo1 = daneDwa.IndexOf("</span>");
  64. pojemnosc = daneDwa.Substring(0, pTo1).Trim();
  65. daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("Zawartość</span>") + "Zawartość</span>".Length).Trim();
  66. int pTo3 = daneDwa.IndexOf("</span>");
  67. zawartosc = daneDwa.Substring(0, pTo3).Trim();
  68.  
  69. if (pojemnosc == zawartosc && pojemnosc != null)
  70. {
  71. ilosc = pojemnosc;
  72. zawartosc = null;
  73. }
  74. else
  75. {
  76. ilosc = zawartosc;
  77. }
  78. lista.Write(ilosc + "\t");
  79.  
  80. lista.Close();
  81. StreamReader test = new StreamReader("lista_test.txt");
  82. richTextBox3.Text = test.ReadLine();
  83. test.Close();
  84.  
  85. //if (obciety.Contains("old-price"))
  86. //{
  87. // obciety = obciety.Remove(0, obciety.IndexOf("class=\"price\">") + "class=\"price\">".Length).Trim();
  88. // int pTo2 = obciety.IndexOf("</span>");
  89. // label10.Text = "Cena przed promocją: " + obciety.Substring(0, pTo2).Trim();
  90. // label7.Text = "";
  91. // obciety = obciety.Remove(0, obciety.IndexOf("class=\"price\" itemprop=\"price\">") + "class=\"price\" itemprop=\"price\">".Length).Trim();
  92. // //int pTo2 = obciety.IndexOf("</span>");
  93. // label11.Text = "Cena promocyjna: " + obciety.Substring(0, pTo2).Trim();
  94. //}
  95. daneDwa = daneDwa.Remove(0, daneDwa.IndexOf("description\">\n") + "description\">\n".Length).Trim();
  96. int pTo2 = daneDwa.IndexOf("</p>");
  97. opis = daneDwa.Substring(0, pTo2).Trim();
  98. StreamWriter tabelaOpisow = new StreamWriter("tabela_opisow.txt");
  99. tabelaOpisow.WriteLine(sku + "\t" + opis);
  100. tabelaOpisow.Close();
  101. richTextBox2.Text = opis;
  102. }
  103. private void textBox1_TextChanged(object sender, EventArgs e)
  104. {
  105.  
  106. }
  107.  
  108. private void richTextBox1_TextChanged(object sender, EventArgs e)
  109. {
  110.  
  111. }
  112.  
  113.  
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement