473,394 Members | 1,722 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,394 software developers and data experts.

Parsing HTML With Muiltiple Foreach Loops

I am attempting to parse an html page but running into problems. The purpose of the parse is to create a program guide for tv programs. I am able to parse each channel, each program, program time and program description but can't seem to get it all together. Meaning I can't get the correct channel with only that channel's shows, time and description into a single array. Here is the php. I will have to post the html example separate, as I keep getting flagged when trying to post it with this post.
Expand|Select|Wrap|Line Numbers
  1. $images= $dom->getElementsByTagName('img');
  2. foreach($images as $img){   
  3.            $icon=   $img ->getAttribute('src'); 
  4.           if( preg_match('/\.(jpg|jpeg|gif)(?:[\?\#].*)?$/i', $icon) ) { //only matching types 
  5.                  $channel[]=$img->getAttribute('alt'); 
  6.               }
  7.               }
  8.               foreach ($childprogram as $programname) 
  9.                      { 
  10.                      $showname[]=$programname->nodeValue;  
  11.                       }
  12.                           foreach($childtime as $programtime){
  13.                               $showtime[]=$programtime->nodeValue;
  14.                           }
  15.                           foreach($childdescrip as $programdescrip){
  16.                                   $showdescrip[]=$programdescrip->nodeValue;
  17.                                   }
  18.  
May 28 '15 #1
2 1217
Dormilich
8,658 Expert Mod 8TB
it would help to know what the source document looks like.

anyways, the code you have shown is insufficient to follow the problem you describe. there are 4 subsequent foreach loops of which only the first one can be understood. from these 4 loops you create 4 separate variables. so I assume that would naturally count as "can't [seem to] get it all together".

it would also help if we knew what the final result should look like.
May 29 '15 #2
Thank you for viewing my questions. In general what I need to do is parse html code extracting a channel name and all programs and times that occur for that channel. The end result would be written to an xml file name by the channel name (ie abc.xml). In each xml there would be the programs and times for that channel.
Now, I can do all the xml code, but I cant figure out how to get the programs for each channel. As you can see from the code each xpath query a different type tag, so there is nothing really connecting the channel with the show or time. There has to be a separate foreach unless an xpath can built created by putting all together.
Attached Files
File Type: pdf HTML NEEDED PARSED.pdf (22.5 KB, 180 views)
May 29 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Jarod_24 | last post by:
I've tried the WebBrowser in the System.Windows.Forms namespace, but it dosen't work when you instanciate an object from a class. It needs a Form to live in to work. My application allready has...
0
by: firelli | last post by:
Hi, I would like to be able to read (parse) an html file into my Java program. Once I'm able to do this, I need to be able to analyse the html code. If you could offer any help in meeting for...
3
by: Seb | last post by:
Hello, I am trying to find some object/function able to take an HTML page (code) as an input, strip out all images, stylesheets and other external references, and returns "cleaned" HTML only...
2
by: pabloski | last post by:
I need to parse real world HTML/XML documents and I found two nice python solution: BeautifulSoup and Tidy. However I found pyXPCOM that is a wrapper for Gecko. So I was thinking Gecko surely...
9
by: sebzzz | last post by:
Hi, I work at this company and we are re-building our website: http://caslt.org/. The new website will be built by an external firm (I could do it myself, but since I'm just the summer student...
7
by: Osiris | last post by:
Just something I would like to share: I just learned the hard way (2 days detective work on a bug) that foreach loops are not at all like for loops, not intuitive at all. BEWARE: arrays and...
7
by: Benjamin | last post by:
I'm trying to parse an HTML file. I want to retrieve all of the text inside a certain tag that I find with XPath. The DOM seems to make this available with the innerHTML element, but I haven't...
2
by: fjm | last post by:
Hello everyone, I need some help and direction with this code. I am trying to have the same functionality that this forum has with regard to the allowable length of time the post (Or in my case,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.