我试图找到下面HTML结构的xpath
<div class="col-xs-6 pg-desc-section">
<p class="boldText">Jewelry</p>
<p data-hostname="nikki stanzione" data-showname="gifts from dallas prince jewelry" data-category="jewelry" data-airtime="11/12/2020 12:00:00 AM">
</p><div class="hidden-xs " data-showscheduleid="23839680">Gifts From Dallas Prince Jewelry</div>
<a class="mobile-showlink visible-xs" data-showscheduleid="23839680" onclick="pgmoreinfo(this); $(this).hide(); $(this).next().show();"> Gifts From Dallas Prince Jewelry</a>
<a class="ab-mobile-showlink" style="display:none;" data-showlink="abTest" data-showscheduleid="23839680" onclick="pgmoreinfo(this);"> Gifts From Dallas Prince Jewelry</a>
<p></p>
</div>
我想要的是第三行中属性数据airtime的值。 我尝试了下面的代码,但它显示了错误的语法。 (请注意数据广播时间是自定义的)
driver.get("https://www.shophq.com/onair/programguide?cm_re=GN-_-ONAIR-_-PROGRAMGUIDE#content")
driver.implicitly_wait(20)
bc=driver.find_elements_by_xpath("//div[@class='col-xs-6 pg-desc-section']/p[@data-category='Jewelry']").data-airtime
在定义xpath时,请帮助找出我在这里做错了什么
find_elements_by_xpath()
返回元素列表。您需要先进行迭代,然后使用get_attribute()
获取值代码块:
要避免同步问题,请使用
WebDriverWait()
您需要导入以下库
所以花了一点时间,;但是,我能够找到你正在搜索的数据。首先,基本web地址是我在初始搜索中使用的地址
一旦我得到了要显示的网站,我就创建了一个方法来获取显示的行数(因为我们需要打印记录的数据)
使用此方法,我可以看到显示了24行。从那里,我滚动到每个元素,然后能够使用
xpath
隔离数据注意
我只为您获取了第一列的数据;但是,使用这段代码,您应该能够得到第2列和第3列
主程序-供参考
样本输出
相关问题 更多 >
编程相关推荐