473,788 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SimpleXML & Google images

Hi, I'm writing a script that would (hopefully) search google images
for whatever, and then return a list of URLs for the image. Right now I
have:

$dom = new DomDocument();

$url = "http://images.google.c om/images?q=hello" ;

$dom->loadHTMLFile($ url);

$sxe = simplexml_impor t_dom($dom);
foreach($sxe->xpath('//img') as $node)
{
echo $node->src;
}

What this is supposed to do (line by line):
Make a new DomDocument
Define $url
load the HTML file from $url
make a simpleXML object from the loaded DOM
go through all the image tags (using a DomNodeList w/ xpath) and print
out the src attribute of the node.

What it does:
Prints nothing.

Just wondering if anyone knew what ws goin on.
Thanks.

Sep 8 '06 #1
2 3802

mouseit101 wrote:
Hi, I'm writing a script that would (hopefully) search google images
for whatever, and then return a list of URLs for the image. Right now I
have:

$dom = new DomDocument();

$url = "http://images.google.c om/images?q=hello" ;

$dom->loadHTMLFile($ url);

$sxe = simplexml_impor t_dom($dom);
foreach($sxe->xpath('//img') as $node)
{
echo $node->src;
}

What this is supposed to do (line by line):
Make a new DomDocument
Define $url
load the HTML file from $url
make a simpleXML object from the loaded DOM
go through all the image tags (using a DomNodeList w/ xpath) and print
out the src attribute of the node.

What it does:
Prints nothing.

Just wondering if anyone knew what ws goin on.
Thanks.
It prints nothing because you have error_reporting disabled in php.ini.
If you enable it you'll see what's going on. For example, here's what
happened when I ran your code:

PHP Warning: DOMDocument::lo adHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseStartT ag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.phpon line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseStartT ag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
/foo.php on line 7

Sep 8 '06 #2

ZeldorBlat wrote:
mouseit101 wrote:
Hi, I'm writing a script that would (hopefully) search google images
for whatever, and then return a list of URLs for the image. Right now I
have:

$dom = new DomDocument();

$url = "http://images.google.c om/images?q=hello" ;

$dom->loadHTMLFile($ url);

$sxe = simplexml_impor t_dom($dom);
foreach($sxe->xpath('//img') as $node)
{
echo $node->src;
}

What this is supposed to do (line by line):
Make a new DomDocument
Define $url
load the HTML file from $url
make a simpleXML object from the loaded DOM
go through all the image tags (using a DomNodeList w/ xpath) and print
out the src attribute of the node.

What it does:
Prints nothing.

Just wondering if anyone knew what ws goin on.
Thanks.

It prints nothing because you have error_reporting disabled in php.ini.
If you enable it you'll see what's going on. For example, here's what
happened when I ran your code:

PHP Warning: DOMDocument::lo adHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseStartT ag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.phpon line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseStartT ag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::lo adHTMLFile(): htmlParseEntity Ref:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
/foo.php on line 7

Ok, Anyone know how to fix it?

Sep 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2622
by: Mr WZ Boson | last post by:
Hello, I hope you can help - I'm a bit new to PHP. My basic problem is with a page (HTML) which is intended to display an image slideshow. On this page there are a number of links to click (one for each slideshow topic) and a "TV screen" to view the results. The images are stored on the server as (big) JPG files - and when they are downloaded for the slideshow, I resize them with a PHP script
2
14771
by: mandric | last post by:
Hello, Can someone please enlighten me on how to preserve the <!]> element when parsing an xml file or string with simplexml. I'm using libxml 2.6.16 and php 5.1.4. I tried a few variations, I found at http://us3.php.net/manual/en/function.simplexml-load-string.php $xml = simplexml_load_string($newsMLString, 'SimpleXMLElement',
0
5576
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
1465
by: Andy | last post by:
Hi, I'm running in to a little issue with SimpleXML, and wondered if anyone knew if it was normal implementation for SimpleXML, or I'm not using a correct flag, or even it's a an issue that should be resolved. I'm actually only just starting to use SimpleXML with any vigor, so I may well be mistaken about what I think it should do... Basically, if you take this simple chunk of XML:
0
1598
by: ty | last post by:
I have a script that takes a xml template then adds data into it using SimpleXMLElement. I then save it using asXML into a mysql database. On my development machine at home it works fine. However, on the host it is changing the tag data into HTML entities. The version of SimpleXMLElement on the host is PHP 5.2.5 and SimpleXML 1.151.2.22.2.35 and the version on my dev machine is PHP 5.2.3 and SimpleXML 1.151.2.22.2.26. Did something...
1
2137
by: =?iso-8859-1?Q?=C1lvaro?= G. Vicario | last post by:
I've spent an hour trying to make SimpleXML work until I realized the problem seems to be namespaces. This code: <?php $xml = simplexml_load_file('foo.xml'); print_r($xml); ?> works fine, unless the XML file contains tags with colons, e.g.:
1
4396
by: duane.lortie | last post by:
I'm writing a routine that fetches XML and attempts to parse some values from it. A condensed entry node of the XML looks like this .. <entry> <title>Some title</title> <author> <name>Author</name> </author> <source:resource url="http://somesite.com?tid=123456"/>
5
2941
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything works fine in FF and IE. It's Chrome I'm having issues with. I understand that Chrome is still somewhat in beta stages, so some bugs might occur. However this seems like something I might have done. So... I used a code that I found on Econym as...
2
3967
anfetienne
by: anfetienne | last post by:
hi, ive got a simplexml code to create xml files it worked before and now when i go to test it i get this error message "Fatal error: Call to undefined function: simplexml_load_string() in /home/theau10/public_html/resources/xmlcreator.php on line 17" i've not changed any of my code but for some reason it comes with an error <? session_start(); if(!$_SESSION){ header("location:index.php"); }
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.