Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Searches for a child node with a given class name
- className: the class name to search for.
- parent: the parent that contains the children.
- */
- function SearchChildNodesByClassName(parent, className) {
- for (var i = 0; i < parent.childNodes.length; i++) {
- if(parent.childNodes[i].className.search(className) != -1) {
- return parent.childNodes[i];
- }
- }
- }
- /*
- Searches for a child node with a given local name (like div, tb, body... etc)
- localName: the local name to search for.
- parent: the parent that contains the children.
- */
- function SearchChildNodesByLocalName(parent, localName) {
- for (var i = 0; i < parent.childNodes.length; i++) {
- if(parent.childNodes[i].localName == localName) {
- return parent.childNodes[i];
- }
- }
- }
- /*
- Get the name of the company from the profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetName(profile) {
- var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
- var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
- var name = SearchChildNodesByClassName(centerRight, "tc_profileTitle");
- return name.textContent;
- }
- /*
- Get the email from a profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetEmail(profile) {
- var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
- var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
- var email = SearchChildNodesByClassName(centerRight, "tc_profileEmail");
- var emailSpan = SearchChildNodesByLocalName(email, "span");
- var emailA = SearchChildNodesByLocalName(emailSpan, "a");
- return emailA.textContent;
- }
- /*
- Get the funding from a profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetFunding(profile) {
- var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
- var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
- var funding = SearchChildNodesByClassName(centerRight, "tc_profileFund");
- var fundSpan = SearchChildNodesByLocalName(funding, "span");
- return fundSpan.textContent;
- }
- /*
- Get the investors from a profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetInvestors(profile) {
- var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
- var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
- var investors = SearchChildNodesByClassName(centerRight, "tc_profileInv");
- var invSpan = SearchChildNodesByLocalName(investors, "span");
- return invSpan.textContent;
- }
- /*
- Get the description from a profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetDescription(profile) {
- var center = SearchChildNodesByClassName(profile, "tcProfileCenter");
- var centerRight = SearchChildNodesByClassName(center, "tcProfileCenterRight");
- var description = SearchChildNodesByClassName(centerRight, "tc_profileDesc");
- var descPara = SearchChildNodesByLocalName(description, "p");
- return descPara.textContent;
- }
- /*
- Gets all the profiles
- */
- function GetProfiles() {
- return [].slice.call(document.getElementsByClassName("tcProfile"));
- }
- /*
- Gets the data from a profile
- profile: a TechCrunch startup from the Startup Alley
- */
- function GetProfileData(profile) {
- return {
- name: GetName(profile),
- email: GetEmail(profile),
- funding: GetFunding(profile),
- investors: GetInvestors(profile),
- description: GetDescription(profile)
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement