用硒提取星级

2024-09-30 18:25:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用Selenium从评论中提取星级,html标记如下:

 <p class="inlineRating starRating"><span class="current-rating" style="width: 80%">
        Current Rating: 4</span></p>

我用selenium做了这个

^{pr2}$

我经常得到的输出是:

Current Rating: 0

我也尝试过xpath方法,scrapy在给页面加外壳时遇到了困难,我正在用python编写代码。请帮忙。在

页面url:http://www.webmd.com/drugs/drugreview-19924-cyclophosphamide+intravenous.aspx?drugid=19924&drugname=cyclophosphamide+intravenous&sortby=3


Tags: 标记htmlselenium评论页面currentclassspan
2条回答

因为有多个评论driver.find_element_css_选择器()打电话可能返回的评论与你想象的不同。你需要先找到评审人,然后才能得到评审。比如should work(如果Python循环正确的话):

user_posts = driver.find_elements_by_css_selector('div.userPost')
for each user_post in user_posts
   effectiveness_rating = user_post.find_element_by_css_selector('#ctnStars > div.catRatings.firstEl.clearfix > p.inlineRating.starRating > span')

为特定评审员寻找有效性星级的xpath是:

//p[@class='reviewerInfo' and contains(text(),'Reviewer: Sandy')]/following-sibling::div//div[contains(@class,'catRatings firstEl clearfix')]//span[@class='current-rating']/text()

你可以对其他类别做同样的事情。。。在

相关问题 更多 >