You are on page 1of 1

Search… Log In Sign Up

Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Home Display selected parts of HTML source of remote page retrieved by curl Ask Question

PUBLIC
I am working on getting the source code of remote page using curl file_get_contents but the asked 5 years, 3 months ago
Stack Overflow

problem is this page have many iframes and ads and i want to get only small part of this page viewed 1,204 times
Tags -1
active 5 years, 3 months ago
Users the page source code is something like that :

Jobs <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir= Related
<head>
TEAMS Retrieve the position (X,Y) of an HTML
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 1036
<meta name="robots" content="noindex,nofollow" /> element
Create Team
<meta name="keywords" content="" />
<meta name="description" content="" /> 629 How to display HTML in TextView?
<meta name="generator" content="" />
<meta content="Tue, 01 Jan 1980 1:00:00 GMT" http-equiv="Expires"> 1115 What characters can be used for up/down
<meta content="no-cache" http-equiv="Pragma"> triangle (arrow without stem) for display in
<title>Kravchuk - Krajinovic (ATP Challenger Karshi)</title> HTML?

</head> 415 How to display request headers with


<body class="contentpane"> command line curl
<script type="text/javascript">
if (top.location != self.location) { 1069 How can I set the default value for an
top.location = 'http://www.streamhunter.eu' HTML <select> element?
}
</script> 1366 Redirect from an HTML page
<style>body{background-color: #000000; text-align: center;}</style>
<style type="text/css"> 0 I am looking for a way to safely insert a
#ad { string to a database?
display: none;
position: absolute; -1 HTML Table auto size chrome
width: 300px;
height: 250px; 23 Cannot display HTML string
margin-left: 215px; /* left pix */
margin-top: -350px; /* top pix */ 0 Inline style reading in .net from a class file
}
#close_ad {
position: absolute; Hot Network Questions
cursor: pointer;
margin-left: 140px; /* left pix */ How to stop rushing writing
margin-top: 0px; /* left pix */
padding: “Equivalent
0px;you relevant ads and job listings. By using our site, you acknowledge that you have read and understand part onPolicy,
my body” or “thePolicy,
equivalent
This site uses cookies to deliver our services and to show our Cookie Privacy and
border: 0px;andand part of my body”?
Join Stack
our Terms Overflow
of Service. Yourtouse
learn, share
of Stack knowledge,
Overflow’s Products build your career.
Services, Email
including the Stack Overflow Network, is Sign Up
subject to theseOR SIGN IN
policies WITH
and terms. Google Facebook
} Let's golf a BIBABOBU decoder

and i want get only this : Company claims hardwire connections are a
security issue

<iframe frameborder="0" marginheight="0" marginwidth="0" height="320" src="http://www.e Zeebus Puzzle #6

What does “all senses cocked” mean?


or Verb for getting something (e.g. information) by
cunning and/or perseverance
<script type="text/javascript"> chname="Zabava"; width="640"; height="385";</script><sc
How old do surviving children need to be to keep
civilization from failing?

how to do so? Partition of Set: Proof

Are any of these Soyuz controls involved in


php html curl separating the orbital module?

share improve this question Warned for next travel to the US by CBP official
asked May 8 '13 at 8:16
user2338253 Invoking Deliberate Values Dissonance
8 5
Is it true that a tarball can change where files are
extracted to regardless of the commands used to
i know about simple html dom but the parts i want to get doesn't have id or any thing to distinguish – extract it?
user2338253 May 8 '13 at 8:17 What magic powers do balrogs have?

For simple text-based tasks to extract minor parts from an HTML source you should prefer regular If conservatism believes in individualism, then why
expressions over actual HTML parsing. You'll need to be more specific about the extraction criteria do conservatives often support regulation of
though before anyone can help with that part. – Niels Keurentjes May 8 '13 at 8:22 personal decisions?

@Niels as you see in my question i want to extract minor parts but my skills in regex in 0 any help will Cumulative total of columns in a matrix or table
be appreciated – user2338253 May 8 '13 at 8:31
Recommended way to move data when changing
hard drive in a Mac
add a comment
How to solve app launch - app is stuck on white
screen
2 Answers active oldest votes
Why would god conduct multiple raptures if he
depends on human beings for worship?

Let's draw the Triforce


You can do this with simple regular expressions, click here for example:
Evenly spaced points on boundary of polygon

0 preg_match_all('#(<iframe.*/iframe>)#i', $code, $matches);


var_dump($matches);
Are there any restrictions on what a national flag
should look like?
preg_match_all('#(<script.*/script>)#i', $code, $matches);
var_dump($matches); Matching two files and printing lines that appear
first time

This will extract (in a very dumb way) all iframes and script elements from the source page. If How to try to get my neighbour to park their car in
you need more specific matching, we'll need more specific criteria, but this could suffice for their actual spot?
your needs.
question feed
share improve this answer answered May 8 '13 at 8:37
Niels Keurentjes
31.6k 5 57 107

yes i need to be more specific to get the iframe or script that has certain word on it only how to do this –
user2338253 May 8 '13 at 8:43

Change it to #(<iframe.*myspecificword.*/iframe>)#i once you figured it out. –


Niels Keurentjes May 8 '13 at 8:45

i use the following code to get and echo the whole source code : ` $html = file_get_contents($url); echo
$html; ?>` how to add your code to instead of echo the whole source only echo the selected iframe –
user2338253 May 8 '13 at 8:55

Just change $code to $html in my sample and inspect the var_dump output to select the correct
array element by index. – Niels Keurentjes May 8 '13 at 8:57

what do you mean by the last part of your comment plz use simple terms – user2338253 May 8 '13 at
9:18

show 10 more comments

You can load your HTML with DOMDocument::loadHTML(), then search it using
DOMXpath::query(). A valid pattern could be //iframe or //script . More information on
0 such XPath search patterns can be found at the Mozilla Developer Network.

share improve this answer answered May 8 '13 at 8:30


str
14.7k 3 50 73

good idea but the page have many //iframe and //script how to select the one i need? – user2338253
May 8 '13 at 8:38

1 @user2338253 you're asking us a question you should answer. We don't know your criteria on
selecting which one you need, so we can't help you with that until you specify it. – Niels Keurentjes May
8 '13 at 8:40

add a comment

Your Answer

Sign up or log in Post as a guest

Sign up using Google Name

Sign up using Facebook Email

required, but never shown


Sign up using Email and Password

Post Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and
cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged php html curl or ask your
own question.

STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Engagement Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Contact Us site design / logo © 2018 Stack Exchange Inc; user
contributions licensed under cc by-sa 3.0 with attribution
Disable Responsiveness required. rev 2018.8.31.31459