Solved

cURL search

Posted on 2013-01-16
8
172 Views
Last Modified: 2013-01-16
Hi experts,

I need to use this for more fields with same name and don't know how to search for them.. Please help.

if (substr($str, strpos($str, 'some text')) !== false) {
$string=substr($str, strpos($str, 'fieldname')+10,20);
$string=substr($string, strpos($string, 'blah')+4,20);
$string=substr($string, strpos($string, '>')+1,100);
$string=substr($string, 0, strpos($string, '<'));
}

Thanks.
0
Comment
Question by:jebbie635
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38781780
Can you be little more clear on the scenario, how you are searching..You said curl in heading where is the curl code and how you are searching
0
 

Author Comment

by:jebbie635
ID: 38781822
I guess it's just php. The first part of my script is curl, sorry for that, am newbie. Please tell me how to search for the fields. This is what i want to do:

first search the source code of a page for 'some text', if found continue to search for labels named the same and then get text if label is found. This code is just for the first label which i already know it's there because it found 'some text'.

if (substr($str, strpos($str, 'some text')) !== false) {
$string=substr($str, strpos($str, 'labelname')+10,20);
$string=substr($string, strpos($string, 'blah')+4,20);
$string=substr($string, strpos($string, '>')+1,100);
$string=substr($string, 0, strpos($string, '<'));
}

How do i search for the next label which has the same name as first one? I need to do this for 20 labels.
0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38782230
read the page and programactically find the list of labels in that page

Then a call a function with required parameters like label,serach term, etc..and return data from that function

Hope its clear
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 38782320
Use the Simple HTML DOM library to parse the page - it's going to be far easier and more flexible. I wrote an article on how to use it to manipulate HTML pages, although you can use the same article to simply extract information from a page after you download it with cURL:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_10277-HTML-Manipulation-Made-Easy.html
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 500 total points
ID: 38782346
The basics are:

// Include the library
require("simple_html_dom.php");

// Assuming $str contains all the HTML from your cURL request
if (strpos($str, 'some text') !== false)
{
   // Parse the HTML
   $html = str_get_html($str);

   // Loop through all <blah> elements
   foreach($html->find("blah") as $blah)
   {
      // Show the contents of that blah tag
      echo "Outertext = " . $blah->outertext . "\n";
      echo "Innertext = " . $blah->innertext . "\n";
      echo "Plaintext = " . $blah->plaintext . "\n";
   }
}
0
 

Author Comment

by:jebbie635
ID: 38783771
$str=post($url, $referer, $agent, $cookie, $vars);

I need to search for this

<div class="someClass">someText</div>

because i have also other <div class="someClass"> with someOtherText which i don't need, and then get the link. I have to do this for 40 possible links.

$link=substr($str, strpos($str, 'someClass')+11,20);
$link=substr($link, strpos($link, 'someText')+14,100);
$link=substr($link, strpos($link, '<a href="')+9,1000);
$link=substr($link, 0, strpos($link, '>'));

Open in new window

This is what i have so far:

$link1=substr($str, strpos($str, 'someClass')+19,20);
$link1=substr($link1, strpos($link1, 'someText')+9,100);
$link1=substr($link1, strpos($link1, '<a href="')+9,1000);
$link1=substr($link1, 0, strpos($link1, '>'));

$link2=substr($str, strpos($str, 'someClass')+19,1000);
$link2=substr($link2, strpos($link2, 'someClass')+9,100);
$link2=substr($link2, strpos($link2, 'someText')+9,100);
$link2=substr($link2, strpos($link2, '<a href="')+9,1000);
$link2=substr($link2, 0, strpos($link2, '>'));
if ($link2) {
some action
}
...
$link40=substr($str, strpos($str, 'someClass')+19,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
...
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someClass')+9,40000);
$link40=substr($link40, strpos($link40, 'someText')+9,100);
$link40=substr($link40, strpos($link40, '<a href="')+9,1000);
$link40=substr($link40, 0, strpos($link40, '>'));
if ($link40) {
some action
}

Open in new window

Can you simplify the search of 'someClass'? This is a lot of code.
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 38784792
Try my previous code, but replace this line:

foreach($html->find("blah") as $blah)

with:

foreach($html->find("div.someClass") as $div)

Then you can check the value of $div->plaintext and compare it to "someText" or whatever you're looking for.
0
 

Author Closing Comment

by:jebbie635
ID: 38784959
It works. Thanks.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now