473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find not the next sibling but the 2nd sibling or find sibling "a" OR sinbling "b"

i have some html which looks like this where i want to scrape out the
href stuff (the www.cnn.com part)

<div class="noFood"> Cheese</div>
<div class="food">Bl ue</div>
<a class="btn" href = "http://www.cnn.com">
so i wrote this code which scrapes it perfectly:

for incident in row('div', {'class':'noFoo d'}):
b = incident.findNe xtSibling('div' , {'class': 'food'})
print b
n = b.findNextSibli ng('a', {'class': 'btn'})
print n
link = n['href'] + "','"

problem is that sometimes the 2nd tag , the <div class="food"> tag , is
sometimes called food, sometimes called drink. so sometimes it looks
like this:

<div class="noFood"> Cheese</div>
<div class="drink">P epsi</div>
<a class="btn" href = "http://www.cnn.com">

how do i alter my script to take into account the fact that i will
sometimes have food and sometimes have drink as the class name? is
there a way to say "look for food or drink" or a way to say "look for
this incident and then find not the next sibling but the 2nd next
sibling" if that makes any sense?

thanks

Jan 18 '06
11 2162
well actually all i want it to do is find the first thing that shows up
whether its class:food or class: drink so that works for me. only
thing is that after it finds class:food i think it runs through the
html again and finds the following class:drink and being that there is
not class tag after that class: drink tag it fails.

Fredrik Lundh wrote:
ho***********@g mail.com wrote:
ok i found something that works. instead of using the def i did this:

for incident in row('div', {'class': 'food' or 'drink' }):

and it worked!


'food' or 'drink' doesn't do what you think it does:
>>> 'food' or 'drink' 'food'
>>> {'class': 'food' or 'drink'}

{'class': 'food'}

</F>


Jan 23 '06 #11
lo************@ gmail.com wrote:
well actually all i want it to do is find the first thing that shows up
whether its class:food or class: drink so that works for me.


what makes you think that looking "food" only will find either "food"
or "drink" ?

</F>

Jan 23 '06 #12

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

Similar topics

3
11312
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- <xsl:for-each select="headdata/extension/person">
2
1873
by: John Smith | last post by:
I have more than 4,000 pieces of email in my Yahoo account. I would like to write a program to download them all. In order to write such a program, I need to know a few things. 1. After I fill out userid, password, and click on "login", what exactly is sent to Yahoo? 2. When I click on "next" to fetch the next mail, what exactly is sent to Yahoo?
3
4144
by: Dmitry Jouravlev | last post by:
Hi, I have a number of C++ solutions in Visual Studio .NET and when i compile them using "Whole Program Optimization", certain projects report a LNK1171 error saying that c2.dll could not be loaded. The error contains the correct path to c2.dll (and it is definately there). This only happens on some projects and only when "whole program optimization" option is turned on. If i turn off this option, the problem goes away. I have other...
3
1501
by: Rudy Ray Moore | last post by:
Hi guys, I often use the "Find" (aka CTRL-F) tool in "Visual Studio .net 2003 7.1 c++". I noticed that that dialog box does not go away when I perform a search (it stays on the screen). This is different from the behavior of VS6. I find this frusterating because a mouse click is required to close the window (I cannot ALT-TAB back to the find window to press ESC).
2
7671
by: Lenonardo | last post by:
Hi. I'm writing a VB.Net application to update multiple Excel Worksheets. I'm using late binding (i.e. all variables are objects + use createobject) I develop the application on an XP machine with Excel 2002 (version 10.0) installed - and the code works fine. I then test the code on a laptop running Excel 2000 (version 9.0) and it
2
2456
by: ntsNews | last post by:
Hi, Using the built in command "Find Next" is there a way to have the Match Drop Down Menu to default to "Start of Field"... or can it be the only option? GCM
1
1794
by: Sion Arrowsmith | last post by:
I have a module which needs to know what directory it's in, and to refer to files in a sibling directory, something like App/src/foo.py wants to read App/data/conf.xml . But I have no idea in what context foo.py is going to be run -- it could be being run as a script, it could be being imported as a module by another script from anywhere in the directory structure, it's even possible someone will have called execfile on it. The following...
3
3991
by: apurvaG | last post by:
Hi All, I am facing a problem while fetching a preceding sibling with some specific name from current node. Following is the sample XML which I am using <Root> <document> <tid>100</tid> <location>SB</location>
3
2194
by: =?ISO-8859-1?Q?Andreas_M=FCller?= | last post by:
Hi! (Python 2.2.3 if this is relevant :-) I have a list of objects with, lets say, the attributes "ID", "x" and "y". Now I want to find the index of list element with ID=10. Of course I can loop through the list manually, but is there a construct like
0
9512
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
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10147
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
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
6770
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
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.