回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我是新来的,希望你能帮忙。我正在学习Python一段时间,目前正在练习web抓取</p>
<p>我尝试了beautifulsoup,直到我被这个脚本击中为止。我使用了一个美化网站,使其可读性</p>
<pre><code><div class="uq-hide js_variationsJSON">
</div>
<div class="pdpStage__column pdp__details js_pdp-details">
<script>
var pdpVariationsJSON =
{
"color-COL05|size-SMA002": {
"id": "419994COL05SMA002000",
"attributes": { "color": "Gray", "size": "XS" },
"availability": { "status": "IN_STOCK", "statusQuantity": "0", "inStock": true, "ats": "19", "inStockDate": "", "availableForSale": true, "purchaseLevel": "", "levels": { "IN_STOCK": 1, "PREORDER": 0, "BACKORDER": 0, "NOT_AVAILABLE": 0 }, "isAvailable": true, "inStockMsg": "1 Item(s) In Stock", "preOrderMsg": "0 item(s) are available for pre-order.", "backOrderMsg": "Back Order 0 item(s)" },
"pricing": {
"showStandardPrice": false,
"isPromoPrice": false,
"standard": 59.9,
"formattedStandard": "£59.90",
"sale": 59.9,
"formattedSale": "£59.90",
"salePriceMoney": {},
"standardPriceMoney": {},
"pricePercentage": "",
"quantities": [
{ "unit": "", "value": 0 }
]
},
"applicablebadges": [
{ "id": "extendedSize", "value": "global.badge.extrasize", "coValue": "XXS-3XL", "class": "grey" }
]
},
"color-COL05|size-SMA003": {
"id": "419994COL05SMA003000",
"attributes": { "color": "Gray", "size": "S" },
"availability": { "status": "IN_STOCK", "statusQuantity": "0", "inStock": true, "ats": "24", "inStockDate": "", "availableForSale": true, "purchaseLevel": "", "levels": { "IN_STOCK": 1, "PREORDER": 0, "BACKORDER": 0, "NOT_AVAILABLE": 0 }, "isAvailable": true, "inStockMsg": "1 Item(s) In Stock", "preOrderMsg": "0 item(s) are available for pre-order.", "backOrderMsg": "Back Order 0 item(s)" },
"pricing": {
"showStandardPrice": false,
"isPromoPrice": false,
"standard": 59.9,
"formattedStandard": "£59.90",
"sale": 59.9,
"formattedSale": "£59.90",
"salePriceMoney": {},
"standardPriceMoney": {},
"pricePercentage": "",
"quantities": [
{ "unit": "", "value": 0 }
]
},
"applicablebadges": [
{ "id": "extendedSize", "value": "global.badge.extrasize", "coValue": "XXS-3XL", "class": "grey" }
]
},
</code></pre>
<p>每次我都得到一个结果,没有一个或一个完整的代码,但没有这一点。我不知道为什么</p>
<p>我这样称呼它</p>
<pre><code>req = Request(link, headers={'User-Agent': 'Mozilla/5.0'})
link= mylink
w = urlopen(req).read()
soup = BeautifulSoup(w, "html.parser")
new = soup.find('div',{'class':'pdpGrid pdp__module pdpStage js_pdpGrid js_pdpGrid- no-quickview'})
print(new)
</code></pre>
<p>如果您有任何建议,我将不胜感激</p>
<p>以下是该网站的链接示例:
'https://www.uniqlo.com/uk/en/product/men-ultra-light-down-jacket-419994COL09SMA005000.html"</p>