473,385 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.com/images?q=hello";

$dom->loadHTMLFile($url);

$sxe = simplexml_import_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 3772

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.com/images?q=hello";

$dom->loadHTMLFile($url);

$sxe = simplexml_import_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::loadHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7

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

Warning: DOMDocument::loadHTMLFile(): htmlParseStartTag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

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

Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
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.com/images?q=hello";

$dom->loadHTMLFile($url);

$sxe = simplexml_import_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::loadHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7

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

Warning: DOMDocument::loadHTMLFile(): htmlParseStartTag: misplaced
<bodytag in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

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

Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
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
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...
2
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,...
0
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...
1
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...
0
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. ...
1
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,...
1
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>...
5
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...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.