2016-09-26 93 views
6

我想尝试我的手和webscraping。我注意到Anglesharp对.Net环境非常有用。我试图从yelp网站上获得所有描述和评分的列表,并且我没有收到任何错误或任何结果。这是一个什么样的HTML看起来像(在“https://www.yelp.ca/biz/walmart-toronto-12”更详细)的一个子集:Anglesharp - 如何从Yelp网站获得评分和评论?

<div class="rating-very-large"> 
    <i class="star-img stars_2" title="2.0 star rating"> 
     <img alt="2.0 star rating" class="offscreen" height="303" src="//s3-media4.fl.yelpcdn.com/assets/srv0/yelp_styleguide/c2252a4cd43e/assets/img/stars/stars_map.png" width="84"> 
    </i> 
     <meta itemprop="ratingValue" content="2.0"> 
</div> 
<p itemprop="description" lang="en">This Walmart still terrifies me<br><br>Baby things can be found on the back right of the lower level. Godspeed.</p> 

<div class="rating-very-large"> 
    <i class="star-img stars_1" title="1.0 star rating"> 
     <img alt="1.0 star rating" class="offscreen" height="303" src="//s3-media4.fl.yelpcdn.com/assets/srv0/yelp_styleguide/c2252a4cd43e/assets/img/stars/stars_map.png" width="84"> 
    </i> 
     <meta itemprop="ratingValue" content="1.0"> 
</div> 
<p itemprop="description" lang="en">Wow I don&#39;t even know where to begin, </p> 

这里是我的查询:

var config = var config = new Configuration().WithJavaScript().WithCss(); 
var parser = new HtmlParser(config); 
var document = await BrowsingContext.New(config).OpenAsync("https://www.yelp.ca/biz/walmart-toronto-12"); 

//Do something with LINQ 
var descriptionListItemsLinq = document.All.Where(m => m.LocalName == "p" && m.Id.Contains("description")); 
foreach (var element in descriptionListItemsLinq) 
{ 
    element.Text().Dump(); 
} 

我如何获得的用户评论列表(描述)和收视率?

回答

0

我查了HTML来源https://www.yelp.ca/biz/walmart-toronto-12。正如我预期的用户评论格式为JSON。在这种情况下,您不应该使用AngleSharp

以下图片摘自HTML来源。

enter image description here

这里是JSON的分析版本:

enter image description here

这是一个JSON,你可以用Newtonsoft.Json反序列化。只需提取JSON并从中读取您需要的内容。