Post-processing script to uses a shared script database to write extracted data to a database


/ Published in: C#
Save to your folder(s)

post-processing script that uses a shared script database to write extracted data to a database


Copy this code and paste it in your HTML
  1. using System;
  2. 02.using mshtml;
  3. 03.using VisualWebRipper;
  4. 04.public class Script
  5. 05.{
  6. 06. //See help for a definition of WrPostprocessArguments.
  7. 07. public static bool Postprocess(WrPostprocessArguments args)
  8. 08. {
  9. 09. try
  10. 10. {
  11. 11. //First we set the SQL we'll use to insert data into the database table.
  12. 12. //The Database connection has already been set by defining a shared script
  13. 13. //database. Visual Web Ripper will automatically open and close the
  14. 14. //database connection.
  15. 15. args.Database.SetSql
  16. 16. ("insert into properties (type,fors,title,description,area)
  17. 17. values (@type,@fors,@title,@description,@area)");
  18. 18. args.Database.PrepareSql();
  19. 19.
  20. 20. //The first table contains the start URL. We only have one start URL in
  21. 21. //this project. ChildTableRows returns all rows in the first child table
  22. 22. foreach(WrDataRow finditRow in args.DataTable.ChildTableRows)
  23. 23. {
  24. 24. //The next child table is the page navigation data table
  25. 25. foreach(WrDataRow pageRow in finditRow.ChildTableRows)
  26. 26. {
  27. 27. //The last child table is where the property data is located
  28. 28. foreach(WrDataRow propertyRow in pageRow.ChildTableRows)
  29. 29. {
  30. 30. args.Database.SetParameterTextValue("@type",
  31. 31. finditRow["type"]);
  32. 32. args.Database.SetParameterTextValue("@fors",
  33. 33. finditRow["fors"]);
  34. 34. args.Database.SetParameterTextValue("@title",
  35. 35. propertyRow["title"]);
  36. 36. args.Database.SetParameterTextValue("@description",
  37. 37. propertyRow["description"]);
  38. 38. args.Database.SetParameterTextValue("@area",
  39. 39. propertyRow["area"]);
  40. 40. args.Database.ExecuteNonQuery();
  41. 41. }
  42. 42. }
  43. 43. }
  44. 44. return true;
  45. 45. }
  46. 46. catch(Exception exp)
  47. 47. {
  48. 48. args.WriteDebug(exp.Message);
  49. 49. return false;
  50. 50. }
  51. 51. }
  52. 52.}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.