0

在 firebug 中,当我在控制台中运行下面的 css 选择器时,我得到一些像这样的输出节点......最终我可以从这些节点中提取信息......

$$("div.skuCol>div.priceBox>div.bFont")

结果 :

[div.bFont, div.bFont, div.bFont, div.bFont, div.bFont, div.bFont,
div.bFont, div.bFont, div.bFont, div.bFont, div.bFont, div.bFont,
div.bFont, div.bFont, div.bFont, div.bFont, div.bFont, div.bFont,
div.bFont, div.bFont, div.bFont, div.bFont, div.bFont, div.bFont,
div.bFont, div.bFont, div.bFont]

如何在 webdriver 中运行上述命令 ...当前我在 python 中执行此操作 ....

    from lxml.cssselect import CSSSelector
    from lxml import etree
    import requests
    from StringIO import StringIO

    #Sorting by low to high
    r = requests.get("http://%s.somewebsite.com/ps/?q=mango&o=pricelth&p=1")
    parser = etree.HTMLParser()
    tree = etree.parse(StringIO(r.content), parser)
    #Note this line...
    sel = CSSSelector("div.skuCol:not([style^='display']) > div.priceBox > div.bFont")
    nodes = sel(tree.getroot())
    s_list = []
    for node in nodes:
        s_list.append(float(node.text.split(" ")[-1]))

    print s_list
4

1 回答 1

3
from selenium import webdriver

driver = webdriver.Firefox()
elements =  driver.find_elements_by_css_selector("div.skuCol>div.priceBox>div.bFont)
#iterate the array and do something with the elements after this
于 2013-05-12T15:18:51.880 回答