gpt4 book ai didi

python-2.7 - 网页中元素的 XPath/CSS 选择器是什么

转载 作者:行者123 更新时间:2023-12-03 06:53:16 25 4
gpt4 key购买 nike

我是 Selenium/Python 的新手。尝试复制数据时卡住了。我正在尝试将数据复制到列表中。每次我尝试在 XPath/CSS 选择器中突出显示元素名称时,它总是给出一条错误消息“找不到元素”。有人可以帮我找到同样的 CSS 选择器/xpath 吗?下面是我为 CSS 选择器尝试过的代码

browser.get("http://ae.bizdirlib.com/taxonomy/term/1493") # Load page
links =[]

link = browser.find_element_by_css_selector("h2 > a")

#for link in links:
link.send_keys(Keys.CONTROL + Keys.RETURN)
link.send_keys(Keys.CONTROL + Keys.PAGE_UP)

elem = browser.find_element_by_css_selector(".content.clearfix>div>fieldset>div>ul>li>span")
elem.send_keys("bar")
elem.send_keys(Keys.CONTROL, 'a') #highlight all in box
c=elem.send_keys(Keys.CONTROL, 'c') #copy
#elem.send_keys(Keys.CONTROL, 'v') #paste
print c

最佳答案

回答您的第二个查询:

from selenium import webdriver

browser = webdriver.Firefox()

browser.implicitly_wait(3)

browser.get("http://ae.bizdirlib.com/taxonomy/term/1493")

links = browser.find_elements_by_css_selector("h2 > a")
links[0].click()

elems = browser.find_elements_by_css_selector("div.content.clearfix > div > fieldset> div > ul > li > span")

for elem in elems:
print elem.text

输出:

=======

Sabbro - F.Z.C
Ajman
United Arab Emirates
Free Zone(Ajman Free Zone)
Click Here to Buy United Arab Emirates Full Data
Business Directory Database Supermarket

关于python-2.7 - 网页中元素的 XPath/CSS 选择器是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32879435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com