在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
答案 0 :(得分: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