Jump to content

gmcust3

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gmcust3's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks a A lot for all the pain you took to code it. <script type="text/javascript"> var omirion = { arrResult: [], tags: ['div', 'h1'], neededClass: ['need', 'greed'], getElements: function () { var tags = this.tags; var neededClass = this.neededClass; for (i = 0; i < tags.length; i++) { var temp = document.getElementsByTagName(tags[i]); for (x = 0; x < temp.length; x++) { for (y = 0; y < neededClass.length; y++) { if (temp[x].className == neededClass[y]) { this.arrResult.push(temp[x]) } } } } return this.arrResult; } } </script> <%php // create a new cURL resource $ch = curl_init(); $fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser $data = curl_exec($ch); $file = fopen("a.txt", "r") or exit("Unable to open file!"); //$fileTxt = "<pre>".htmlspecialchars(file_get_contents("a.txt"))."</pre>"; while(!feof($file)) { $html = fgets($file); $content = getTextBetweenTags('h1', $html); foreach( $content as $itemName ) { echo "<SCRIPT>var eles = omirion.getElements()</SCRIPT>"; } } fclose($file); // close cURL resource, and free up system resources curl_close($ch); %> This is the Code which I am trying !!
  2. Sure. Google is My best Friend. Its always by my side even my wife is Not next to me
  3. Thanks a Lot . My motive to Extract Data form White Pages and Display that in Notepad. Different Ways can be 10000 , but I just need to get it solve :-) { Matters is Result }
  4. I am basically Call Center Guy. I love to play with everything but Not master in Any particular code. Though I used to Code in VB andASP long back.
  5. I posted it in PHP forum , But topic was moved to Java Script :-(
  6. Tried below code also : <?php /** * * @get text between tags * * @param string $tag The tag name * * @param string $html The XML or XHTML string * * @param int $strict Whether to use strict mode * * @return array * */ function getTextBetweenTags($tag, $html, $strict=0) { /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ if($strict==1) { $dom->loadXML($html); } else { $dom->loadHTML($html); } /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the tag by its tag name ***/ $content = $dom->getElementsByTagname($tag); /*** the array to return ***/ $out = array(); foreach ($content as $item) { /*** add node value to the out array ***/ $out[] = $item->nodeValue; } /*** return the results ***/ return $out; } ?> <?php // create a new cURL resource $ch = curl_init(); $fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser $data = curl_exec($ch); $file = fopen("a.txt", "r") or exit("Unable to open file!"); //$fileTxt = "<pre>".htmlspecialchars(file_get_contents("a.txt"))."</pre>"; while(!feof($file)) { $html = fgets($file); $content = getTextBetweenTags('h1', $html); $content1 = getTextBetweenTags('street_line', $html); foreach( $content as $itemName ) { echo "Name : " .$itemName.'<br />'; foreach( $content1 as $itemAdd) { echo "Address : " .$itemAdd.'<br />'; } } } fclose($file); // close cURL resource, and free up system resources curl_close($ch); ?> But probably not designed to get a tag based on sub-name, only on tag type.
  7. Tried : $file = fopen("a.txt", "r") or exit("Unable to open file!"); while(!feof($file)) { $regex="/clearfix\"><h1 class(.*)<\/h1><\/div><div class/"; preg_replace($regex,"",fgets($file)); } How to Get Address as there are many tags with span ? Code: <span class="street_line">398 Lonsdale St</span> Code: <span class="locality">Melbourne</span> Code: <span class="state">VIC</span> Code: <span class="postcode">3000</span> <div class="address"><span class="street_line">25 Spring St</span><span class="locality">Melbourne</span><span class="state">VIC</span><span class="postcode">3000</span></div> This div has Address but There are Other Div also. Just thinking How to Extract Address One Only . Primary is <div class="address"> But Before address div, there are many more div.
  8. I am there all day, Its just 9:56 am Now :-)
  9. Thanks for the Code. Any Working Example ( If any ) ? My Motive : I have saved the HTML content in a Notepad. Now, I want to Read the Notepad by looping and Extracting the Value between the Tag and Display the Content between those tags. Content saved : http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC Using : // create a new cURL resource $ch = curl_init(); $fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0);
  10. I agree. Sorry for the Confusions. It has <H1 class=" ">Smith Colin P</H1></DIV> getElementsByTagName should work with above tag ?
  11. <DIV class="entry clearfix " id=entry_9> <DIV class="entry_title clearfix"> <H1 class=" ">Smith Colin P</H1></DIV> <DIV class=full_listing> <DIV class=blocks> <DIV class="block indent-level-0" id=entry_9_block_0> <DIV class=share_link wpol:contactPointId="711357117V00W" wpol:entryId="711357117V00W"> <DIV class=save_menu> <DIV class=icon></DIV></DIV> <DIV class=share_menu> <DIV class=icon></DIV></DIV><A class=screen_reader_only href="http://192.168.0.2/mobile/send-to-mobile-accessible?entryId=711357117V00W&listingId=711357117V00W&searchType=R&channel=WP" rel=nofollow name=Smith>Send this listing to your mobile</A></DIV> <SPAN class="phone_number ">(03) 9650 4978</SPAN> <DIV class=address><SPAN class=street_line>118 Russell St</SPAN> <SPAN class=locality>Melbourne</SPAN><SPAN class=state>VIC</SPAN> <SPAN class=postcode>3000</SPAN></DIV> Now trying to parse above code.
  12. Lets say I have a Tag as <div class=name>MyName</div> <div class=address>MyAddress</div> How to Extract name Value Only and Not the Address ?
  13. Tried But No Error, No Result. <?php ini_set('display_errors',true);//Just in case we get some errors, let us know.... // create a new cURL resource $ch = curl_init(); $fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); $file = fopen("a.txt", "r") or exit("Unable to open file!"); while(!feof($file)) { $regex="/clearfix\"><h1 class(.*)<\/h1><\/div><div class/"; preg_replace($regex,"",fgets($file)); } fclose($file); // close cURL resource, and free up system resources curl_close($ch); ?>
  14. I am looking at http://www.phpro.org/examples/Get-Text-Between-Tags.html
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.