0

ok i am very new to this. and iv been trying to figure out how to get the value of title with pure javascript and i believe xpath might work best speed wise.

<ul class="room_info">
    <li>
        <span>Value:</span>
        <span class="value">
            <span class="shorthand shorthand-m">
                <span title="$60,760,150,000,000,000">$60,760,150,000&nbsp;M</span>
            </span>
        </span>
    </li>
    <li>
</ul>

this is the full xpath expression

html/body/div[3]/div[2]/div[3]/div[15]/div[1]/div/div[1]/div/div[1]/div[1]/ul[1]/li[1]/span[2]/span/span

what i will want to do is use imacros and this script to get the number in quotes to determine rather to click a button. so if the number is to high it will wait until it is smaller then continue. but right now i just need to figure out how to get the value of title.

this is the link to the page i want to run it on. http://www.tagged.com/apps/pets.html#cashruns/3646/


Generally speaking, float is a relative positioning statement, since it specifies the position of the element relative to its parent container (floating to the right or left). This means it's incompatible with the position:absolute property, because position:absolute is an absolute positioning statement. You can either float an element and allow the browser to position it relative to its parent container, or you can specify an absolute position and force the element to appear in a certain location. Specifically, an element with position:absolute will be placed at whatever offset you specify (with left, right, top, or bottom) from the position of its nearest ancestor (containing element) with a position property, regardless of whether it has a float property or not. If it doesn't have any ancestors with a position property, it will be placed at your specified offset from the edge of the screen.

If you want an absolutely-positioned element to appear on the right side of its parent div, you can use position: absolute; right: 0; -- as long as the parent div has a position property such as position:relative. If the parent div doesn't have a position property, though, this won't work, and you'll need to stick to float:right.

4

3 回答 3

0

要使用 javascript 评估 xpath,您可以使用document.evaluate()函数。你可以在这里获得更多信息

function getSpanTitle() {
   var result = document.evaluate("//span[@class='shorthand shorthand-m']/span/@title", document, null, XPathResult.ANY_TYPE, null);   
   var title = result.iterateNext();   
   alert(title.textContent);
}

另请注意,我使用了相对 xpath,因为//span[@class='shorthand shorthand-m']/span/@title它比绝对 XPath 更健壮。

于 2012-07-05T04:57:55.237 回答
0

你可以抓取html标签

tag pos=1 type=span attr=title:* extract=htm

然后在eval中使用 javascript slice() 方法提取所需的数据

于 2012-12-27T22:19:37.553 回答
0

使用@attribute-name 选择属性。在您的示例中 //span/@title 可能有效,但您可能会使用更具选择性的 xpath。

某些 XPath 实现不支持属性,因此请参阅 iMacros 文档。

于 2012-07-04T18:40:50.470 回答