DHL Express Tracking Query

Source: Internet
Author: User

?

Description: The main use of regular expression parsing.

Returns a list of trace steps.

  1. Public class Trackingdata
  2. ???? {
  3. ???????? Public string Time { get; set; }
  4. ???????? Public string Context { get; set; }
  5. ????}
  6. ?
  7. ???? Public class Dhlexpresstrackinghelper
  8. ???? {
  9. ???????? Private Static string urlformat = "http://webtrack.dhlglobalmail.com/?trackingnumber={0}";
  10. ?
  11. ???????? Public Static List<trackingdata> gettrackingdata (string trackcode)
  12. ???????? {
  13. ???????????? //trackcode = "A150529020091";
  14. ???????????? Webmocker Dhlmocker = new webmocker ();
  15. ???????????? var url = string. Format (Urlformat, Trackcode);
  16. ???????????? var html = dhlmocker.get (URL);
  17. ?
  18. ???????????? //1
  19. ???????????? var Patternoltag = "<ol.*?> (? <olvalue>.*?) </ol>";
  20. ???????????? var match = Regex.match (HTML, Patternoltag, Regexoptions.multiline | Regexoptions.singleline);
  21. ???????????? if (Match. Success)
  22. ???????????? {
  23. ???????????????? var olvalue = match. groups["olvalue"]. Value;
  24. ???????????????? return Parsetrackingdata (Olvalue);
  25. ????????????}
  26. ?
  27. ???????????? return New List<trackingdata> ();
  28. ????????}
  29. ?
  30. ???????? Private Static List<trackingdata> parsetrackingdata (string olvalue)
  31. ???????? {
  32. ???????????? var Patternlitag = "<li.*?" Class=\ "(? <classname>.*?) \ ".*?> (? <content>.*?) </li>";
  33. ?
  34. ???????????? var list = new list<trackingdata> ();
  35. ?
  36. ???????????? string dateprefix = null;
  37. ?
  38. ???????????? foreach (Match item in Regex.Matches (Olvalue, Patternlitag, Regexoptions.singleline | Regexoptions.multiline | Regexoptions.ignorecase))
  39. ???????????? {
  40. ???????????????? var className = Item. groups["className"]. Value;
  41. ???????????????? var content = Item. groups["content"]. Value;
  42. ???????????????? if (ClassName = = "timeline-date")
  43. ???????????????? {
  44. ???????????????????? Dateprefix = content;
  45. ????????????????}
  46. ???????????????? Else if (Classname.contains ("timeline-event"))
  47. ???????????????? {
  48. ???????????????????? var pp = "<div.*?class=\" (? <divclassname>.*?) \ ".*?> (? <divcontent>.*?) </div>";
  49. ?
  50. ???????????????????? Trackingdata trackingdata = null;
  51. ?
  52. ???????????????????? foreach (Match subitem in regex.matches (content, pp, regexoptions.singleline | Regexoptions.multiline | Regexoptions.ignorecase))
  53. ???????????????????? {
  54. ???????????????????????? var divclassname = subitem.groups["divclassname"]. Value.trim ();
  55. ???????????????????????? var subcontent = subitem.groups["divcontent"]. Value.trim ();
  56. ???????????????????????? if (Divclassname = = "timeline-time")
  57. ???????????????????????? {
  58. ???????????????????????????? Subcontent = Regex.Replace (subcontent, "<[^<]*>", "");
  59. ???????????????????????????? Trackingdata = new trackingdata ();
  60. ???????????????????????????? Trackingdata.time = Dateprefix + "" + subcontent;
  61. ????????????????????????}
  62. ???????????????????????? Else if (Divclassname = = "timeline-location")
  63. ???????????????????????? {
  64. ???????????????????????????? Trackingdata.context + = subcontent +"";
  65. ????????????????????????}
  66. ???????????????????????? Else if (Divclassname = = "timeline-description")
  67. ???????????????????????? {
  68. ???????????????????????????? Trackingdata.context + = subcontent +"";
  69. ????????????????????????}
  70. ???????????????????????? //else if (divclassname = = "Timeline-location timeline-location-responsive")
  71. ???????????????????????? //{
  72. ???????????????????????? //Trackingdata.description + = subcontent;
  73. ???????????????????????? //}
  74. ????????????????????}
  75. ?
  76. ???????????????????? List. ADD (Trackingdata);
  77. ????????????????}
  78. ????????????}
  79. ?
  80. ???????????? //foreach (var item in list)
  81. ???????????? //{
  82. ???????????? //Console.WriteLine (item. DateString + "--" + Item. Description);
  83. ???????????? //}
  84. ???????????? return list;
  85. ????????}
  86. ????}

DHL Express Tracking Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.