我正在尝试使用python BeautifulSoup https://paytm.com/shop/p/masha-mauve-satin-nighty-WNIGHW000NT14_45BBPPFR?src=search-grid&tracker=autosuggest%7Cundefined%7Cmasha%20nighty%7Cgrid%7CSearch%7C1从paytm网页抓取数据。 我可以废弃所有使用直接类名的字段,但有些字段使用的是angularjs属性,我不知道该怎么做。
我知道如何使用定义的类来抓取跨度的数据: -
mrp = link_soup.find_all("span" , class_="price")[0].string.strip()
但是不知道如何为上述代码做同样的事情。
我想从中获取数据的代码: -
<span ng-if="!product.product.isOnlyCarCategory">Buy for Rs 329</span>
我想从这个范围中刮掉329号。
整个代码: -
<div itemprop="offers" itemscope="itemscope" itemtype="https://schema.org/Offer" class="buy-bar">
<button class="md-raised fl md-button md-default-theme" ng-transclude="" type="button" ng-show="!product.product.notSellable && !product.product.preorder" ng-click="product.buyProduct();_gaq.push(['_addTrans','3523347','Bboy Body Wears', '329','', '0', '', '', 'India'])" ng-class="{'dealBtn' : product.product.vertical_id == 5 ,'cartupdating' : product.isCartUpdating }" ng-disabled="product.isCartUpdating || !product.product.instock" tabindex="0" aria-hidden="false" aria-disabled="false"><span ng-show="!product.product.add_qty_using_price && product.product.vertical_id !=5" aria-hidden="false">
<span ng-if="!product.product.isOnlyCarCategory">Buy for Rs 329</span>
<meta itemprop="price" content="">
<div>
<span ng-show="product.product.actual_price != product.product.offer_price" class="strike" aria-hidden="false">Rs. 749</span><span ng-show="product.product.actual_price != product.product.offer_price" aria-hidden="false" class=""> | 56% Discount</span></div>
<meta itemprop="pricecurrency" content="INR"></span><span ng-show="!product.product.add_qty_using_price && product.product.vertical_id ==5" aria-hidden="true" class="ng-hide"><span> Buy for Rs.329</span>
<meta itemprop="price" content="">
<div><span ng-show="product.product.attributes.deal_mrp" class="strike ng-hide" aria-hidden="true">Rs. </span><span ng-show="product.product.attributes.discounted_MRP" aria-hidden="true" class="ng-hide"> | Pay at store ~ Rs. </span><span ng-show="product.product.attributes.discount_perc" aria-hidden="true" class="ng-hide"> | Saving upto %</span></div>
<meta itemprop="pricecurrency" content="INR"></span><span ng-show="product.add_qty_using_price" aria-hidden="true" class="ng-hide"><span class="text"></span></span></button>
<button class="md-raised fl md-button md-default-theme ng-hide" ng-transclude="" type="button" ng-show="!product.product.notSellable && product.product.preorder" ng-click="product.buyProduct();_gaq.push(['_addTrans','3523347','Bboy Body Wears', '329','', '0', '', '', 'India'])" ng-class="product.isCartUpdating ? 'cartupdating': ''" ng-disabled="product.isCartUpdating || !product.product.instock ? "disabled": """ tabindex="0" aria-hidden="true" aria-disabled=""><span>Preorder Now For Rs. 329
<meta itemprop="price" content="329">
<div><span ng-show="product.product.actual_price != product.product.offer_price" class="strike" aria-hidden="false">Rs. 749</span><span ng-show="product.product.actual_price != product.product.offer_price" aria-hidden="false" class=""> | 56% Discount</span></div>
<meta itemprop="pricecurrency" content="INR"></span></button>
<div ng-show="product.product.notSellable" class="md-button md-raised fr ng-hide" aria-hidden="true"><a ng-href="" target="_blank"><span class="text"></span></a></div>
</div>
有没有解决方案?
答案 0 :(得分:0)
使用此link可获得更好的概述。
要更准确地回答您的问题, Paytm 会获取有关该产品的js文件中的数据。以下链接提供了有关 Paytm 中列出的任何产品的数据:
https://catalog.paytm.com/v1/p/的产品网址&安培;回调= angular.callbacks._0&安培;信道=纸幅放大器;版本= 2
您给出的链接:
https://paytm.com/shop/p/masha-mauve-satin-nighty-WNIGHW000NT14_45BBPPFR?src=search-grid&tracker=autosuggest%7Cundefined%7Cmasha%20nighty%7Cgrid%7CSearch%7C1。
product-url :
?马沙-淡紫色缎-nighty-WNIGHW000NT14_45BBPPFR SRC =搜索网格&安培;跟踪=自动提示%7Cundefined%7Cmasha%20nighty%7Cgrid%7CSearch%7C1
希望它可以帮到你。