Python beautifulsoup返回空值

Python beautifulsoup返回空值,python,python-2.7,web-scraping,beautifulsoup,pyqt4,Python,Python 2.7,Web Scraping,Beautifulsoup,Pyqt4,我正在使用Jupyter Python 2.7 我试图从这个网站检索数据,使用beautifulsoup和lxml解析器来获取描述或价格,一切都进行得很顺利 地点=“” 然而,当我试图抓取评论或审阅者的位置时,我无法检索到任何内容,只有一个空列表[] 我还尝试了PyQt4先渲染它,但它仍然不起作用。我现在该怎么修 我的代码附在下面 import PyQt4 from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.Qt

我正在使用Jupyter Python 2.7 我试图从这个网站检索数据,使用beautifulsoup和lxml解析器来获取描述或价格,一切都进行得很顺利

地点=“”

然而,当我试图抓取评论或审阅者的位置时,我无法检索到任何内容,只有一个空列表[]

我还尝试了PyQt4先渲染它,但它仍然不起作用。我现在该怎么修

我的代码附在下面

import PyQt4
from PyQt4.QtGui import *  
from PyQt4.QtCore import *  
from PyQt4.QtWebKit import * 
import sys
from lxml import html
from bs4 import BeautifulSoup
import os
import requests

site = 'https://www.bedbathandbeyond.com/store/product/dyson-v7-motorhead-cord-free-stick-vacuum-in-fuchsia-steel/1061083288?brandId=162'

class Render(QWebPage):     
    def __init__(self, url):
        self.app = QApplication(sys.argv)  
        QWebPage.__init__(self)  
        self.loadFinished.connect(self._loadFinished)  
        self.mainFrame().load(QUrl(url))  
        self.app.exec_()   
    def _loadFinished(self, result):  
        self.frame = self.mainFrame()  
        self.app.quit()
r = Render(site)  
result = r.frame.toHtml()
formatted_result = str(result.toAscii())
tree = html.fromstring(formatted_result)
soup = BeautifulSoup(formatted_result,'lxml')
soup.find_all('span', class_ = 'BVRRValue BVRRUserLocation')#return value is []

非常感谢

我很快检查了引用的URL,只有在您单击“评级和评论”选项卡后,才能通过异步调用加载评论。因此,如果您只是加载页面而没有任何额外的导航,那么评论将不会出现在DOM中(因此也不会出现在您正在使用BeautifulSoup解析的HTML中)

因此,一个解决方案是,在获取HTML并将其传递给BeautifulSoup之前,只需点击“Ratings&Review”

或者,您也可以进行相同的异步调用,自己获取评论。通过对此页面执行GET请求来检索评论的第一页:
https://bedbathandbeyond.ugc.bazaarvoice.com/2009-en_us/1061083288/reviews.djs?format=embeddedhtml&page=1&scrollToTop=true


您可以轻松地为BedBath和Bedbath以外的每个产品构建此URL,因为您只需要拥有产品id(本例中为1061083288),可以使用id为
prodRatings
的div从原始DOM轻松获取该id。它包含一个带有产品id的隐藏输入字段。您只需将其替换为以前的URL,即可获取所有产品的所有评论。

您好,非常感谢您的回答,我明白了!所以问题不在于JS渲染,对吗?