logo
down
shadow

xpath preceding child issue


xpath preceding child issue

By : Dusty
Date : November 22 2020, 10:31 AM
hope this fix your issue Let's make it simpler.
Each division is represented with div with a mod-teams-list-medium class. Each division div consist of 2 parts:
code :
for division in response.xpath('//div[@id="content"]//div[contains(@class, "mod-teams-list-medium")]'):
    division_name = division.xpath('.//div[contains(@class, "mod-header")]/h4/text()').extract()[0]
    print division_name
    print 

    for team in division.xpath('.//div[contains(@class, "mod-content")]//li'):
        team_name = team.xpath('.//h5/a/text()').extract()[0]

        print team_name
    print "------"
Atlantic

Boston Celtics
Brooklyn Nets
New York Knicks
Philadelphia 76ers
Toronto Raptors
------
Pacific

Golden State Warriors
Los Angeles Clippers
Los Angeles Lakers
Phoenix Suns
Sacramento Kings
------
...


Share : facebook icon twitter icon
Issue while using Preceding axis in XPath and XSLT

Issue while using Preceding axis in XPath and XSLT


By : Plagioclase
Date : March 29 2020, 07:55 AM
will help you You are correct about which node is the context node, and that node does have 6 preceding elements:
The first element. The four elements inside that. The element immediately before the context node.
code :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" />
 <xsl:template match="/">
   <xsl:for-each select="/Order/Item[ItemName='Ipad']/ItemName/preceding::*">
     <xsl:value-of select="concat(name(), '&#xA;')" />
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>
XPath preceding-sibling to find child based on parent's sibbling's value?

XPath preceding-sibling to find child based on parent's sibbling's value?


By : malik
Date : March 29 2020, 07:55 AM
With these it helps
I want to select the input, for which there is a label with a certain text.
code :
//input[@id = //label[text()="Text To Match"]/@for]
//input[@id = //label[@for="input_randomnumber"]/@for]
XPath with not contains and preceding

XPath with not contains and preceding


By : Sunil Chauhan
Date : March 29 2020, 07:55 AM
it helps some times Assuming that Elbrus III CPU should really be Elbrus II CPU in your example of selected text, this should work...
code :
//text()[(contains(.,'Intel') or contains(.,'AMD') or contains(.,'Elbrus')) and preceding::h1[1][span[contains(@id,'One')]]]
PHP/XPATH - Find PRECEDING-SIBLING of PARENT and get its' CHILD

PHP/XPATH - Find PRECEDING-SIBLING of PARENT and get its' CHILD


By : Александр Ершов
Date : March 29 2020, 07:55 AM
like below fixes the issue I've been trying to figure this our for days, but I simply cannot seem to get it to work. , To get the nearest preceding sibling, use this XPath query:
code :
//type[contains(text(), "BBB")]/parent::item/preceding-sibling::item[1]
$xml = "<root>
    <itemList>
        <item>
            <name>A</name>
            <type>AAA</type>
        </item>
        <item>
            <name>B</name>
            <type>BBB</type>
        </item>
        <item>
            <name>C</name>
            <type>CCC</type>
        </item>
    </itemList>
</root>";

$xml = new SimpleXMLElement($xml);

$res = $xml->xpath('//type[contains(text(), "BBB")]/parent::item/preceding-sibling::item[1]');
echo "{$res[0]->name} ({$res[0]->type})".PHP_EOL;

$res = $xml->xpath('//type[contains(text(), "CCC")]/parent::item/preceding-sibling::item[1]');
echo "{$res[0]->name} ({$res[0]->type})";
$xml = "<root>
    <itemList>
        <item>
            <name>A</name>
            <type>AAA</type>
        </item>
        <item>
            <name>B</name>
            <type>BBB</type>
        </item>
        <item>
            <name>C</name>
            <type>CCC</type>
        </item>
        <item>
            <name>C</name>
            <type>DDD</type>
        </item>
    </itemList>
</root>";

$xml = new SimpleXMLElement($xml);

$res = $xml->xpath('//type[contains(text(), "DDD")]/parent::item/preceding-sibling::item');
var_dump($res);
array (size=3)
  0 => 
    object(SimpleXMLElement)[2]
      public 'name' => string 'A' (length=1)
      public 'type' => string 'AAA' (length=3)
  1 => 
    object(SimpleXMLElement)[3]
      public 'name' => string 'B' (length=1)
      public 'type' => string 'BBB' (length=3)
  2 => 
    object(SimpleXMLElement)[4]
      public 'name' => string 'C' (length=1)
      public 'type' => string 'CCC' (length=3)
$res = $xml->xpath('//type[contains(text(), "DDD")]/parent::item/preceding-sibling::item');
$total = count($res);
echo "{$res[$total - 1]->name} ({$res[$total - 1]->type})".PHP_EOL;
How to select preceding-sibling elements by a child's attribute in XPath

How to select preceding-sibling elements by a child's attribute in XPath


By : user3012955
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further It looks like I was wanting to use the following-sibling axis instead of preceding-sibling. The XPath below, which differs from the other answer only in using following-sibling, gives the desired result.
code :
//div[@class='mw-parser-output']/*[count(following-sibling::h2//span[.='References'])>0]
Related Posts Related Posts :
  • How to perform cartesian product with Tensorflow?
  • Multiple independent random number streams from single seed
  • I Need a simple and short python3 code that count secounds in a background process
  • No module named constants
  • from django 1.4 to django 1.5- argument 'verify_exists' what s replacement?
  • Slash replacement inside a raw string
  • Reordering columns/rows of a pivot_table?
  • MySQLdb.cursors.Cursor.execute does not work
  • Python module being reimported when imported at different places
  • Is the Session object from Python's Requests library thread safe?
  • Python Regex: Finding First and Last Names
  • Order by selection in List view of OpenERP 7.0
  • Reading input values in ipython notebook
  • List of dictionaries - how to read a specific value in a dictionary
  • writing os.system output to file
  • Create dictionary from points list and multiple attribute lists
  • How to write a table line by line with for loop
  • Map projection and forced interpolation
  • Django FBV's "render_to_response" equivalent in Class-Based-View?
  • Paramiko raises "SFTPError: Garbage packet received"
  • python pandas operations on columns
  • python list appending is not working
  • Speeding up matplotlib scatter plots
  • For each element of the list find closest date from a different list
  • How to prepend new rows at the beginning of an existing csv file?
  • how to make database robust to process kills with sqlite postgress and sqlalchemy?
  • finding a set of ranges that a number fall in
  • New line in python print() function
  • How to clear os.environ value for only one Variable in Python
  • Why does python append a modulo(%) operator to the end of a newly opened file?
  • recursive function or non-recursive that doesnt use 2 ** approach
  • Extract floats from a String using regular expression
  • How to solve: ImportError: No module named django.core.wsgi in Apache2 log?
  • What's the most concise way to include multiple statements in a Python switch case?
  • python xml pretty print not working
  • Can we use NumPy in writing a website?
  • Called bashscript doesn't start up GNU screen session
  • Reading fortran direct access data and writing formatted data - faster with python than with fortran?
  • Language supporting nested definition of functions
  • Find elements which exists in the most of the lists
  • Templating library in node.js similar to Jinja2 in Python?
  • Python Syntax Error, 'break' is outside the loop
  • Replacing spaces with hyphens
  • How to open a csv file in Microsoft Excel in Python?
  • ModuleNotFoundError: No module named 'users'
  • Interpolating with multiple y-values
  • Import warning PACKAGE.egg is added to sys.path
  • Is there a key for the default namespace when creating dictionary for use with xml.etree.ElementTree.findall() in Python
  • Using fill_between() with a Pandas Data Series
  • How to build a lookup table for tri-linear interpolation in NumPy?
  • Matrix vector multiplication along array axes
  • Can a cookiejar object be pickled?
  • __init__.py in project folder breaks nose tests
  • Comparing times with sub-second accuracy
  • advanced search using HayStack + Solr in Django?
  • Base test case class for python unittest
  • The PyData Ecosystem
  • Finding unique entries with oldest time stamp
  • Custom filesize format with Python Humanize?
  • Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org