Advertisement
gregv21v

TechCrunchAPI

Oct 4th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. /*
  2. Searches for a child node with a given class name
  3.  
  4. className: the class name to search for.
  5. parent: the parent that contains the children.
  6. */
  7. function SearchChildNodesByClassName(parent, className) {
  8. for (var i = 0; i < parent.childNodes.length; i++) {
  9. if(parent.childNodes[i].className.search(className) != -1) {
  10. return parent.childNodes[i];
  11. }
  12. }
  13. }
  14.  
  15. /*
  16. Searches for a child node with a given local name (like div, tb, body... etc)
  17.  
  18. localName: the local name to search for.
  19. parent: the parent that contains the children.
  20. */
  21. function SearchChildNodesByLocalName(parent, localName) {
  22. for (var i = 0; i < parent.childNodes.length; i++) {
  23. if(parent.childNodes[i].localName == localName) {
  24. return parent.childNodes[i];
  25. }
  26. }
  27. }
  28.  
  29.  
  30.  
  31.  
  32. /*
  33. Get the name of the company from the profile
  34.  
  35. profile: a TechCrunch startup from the Startup Alley
  36. */
  37. function GetName(profile) {
  38. var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
  39. var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
  40. var name = SearchChildNodesByClassName(centerRight, "tc_profileTitle");
  41. return name.textContent;
  42. }
  43.  
  44. /*
  45. Get the email from a profile
  46.  
  47. profile: a TechCrunch startup from the Startup Alley
  48. */
  49. function GetEmail(profile) {
  50. var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
  51. var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
  52. var email = SearchChildNodesByClassName(centerRight, "tc_profileEmail");
  53. var emailSpan = SearchChildNodesByLocalName(email, "span");
  54. var emailA = SearchChildNodesByLocalName(emailSpan, "a");
  55. return emailA.textContent;
  56. }
  57.  
  58. /*
  59. Get the funding from a profile
  60.  
  61. profile: a TechCrunch startup from the Startup Alley
  62. */
  63. function GetFunding(profile) {
  64. var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
  65. var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
  66. var funding = SearchChildNodesByClassName(centerRight, "tc_profileFund");
  67. var fundSpan = SearchChildNodesByLocalName(funding, "span");
  68. return fundSpan.textContent;
  69. }
  70.  
  71. /*
  72. Get the investors from a profile
  73.  
  74. profile: a TechCrunch startup from the Startup Alley
  75. */
  76. function GetInvestors(profile) {
  77. var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
  78. var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
  79. var investors = SearchChildNodesByClassName(centerRight, "tc_profileInv");
  80. var invSpan = SearchChildNodesByLocalName(investors, "span");
  81. return invSpan.textContent;
  82. }
  83.  
  84. /*
  85. Get the description from a profile
  86.  
  87. profile: a TechCrunch startup from the Startup Alley
  88. */
  89. function GetDescription(profile) {
  90. var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
  91. var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
  92. var description = SearchChildNodesByClassName(centerRight, "tc_profileDesc");
  93. var descPara = SearchChildNodesByLocalName(description, "p");
  94. return descPara.textContent;
  95. }
  96.  
  97.  
  98. /*
  99. Gets all the profiles
  100.  
  101. */
  102. function GetProfiles() {
  103. return [].slice.call(document.getElementsByClassName("tcProfile"));
  104. }
  105.  
  106. /*
  107. Gets the data from a profile
  108.  
  109. profile: a TechCrunch startup from the Startup Alley
  110. */
  111. function GetProfileData(profile) {
  112. return {
  113. name: GetName(profile),
  114. email: GetEmail(profile),
  115. funding: GetFunding(profile),
  116. investors: GetInvestors(profile),
  117. description: GetDescription(profile)
  118. };
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement