第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Scrapy 請求得到一些響應(yīng),但不是全部

Scrapy 請求得到一些響應(yīng),但不是全部

達令說 2023-12-08 16:44:37
我正在抓取一個在同一個 <@div (bold) xpath 中有 36 個 <@hrefs 的頁面,所以當(dāng)我嘗試獲取這些內(nèi)容時,即使在 scrapy shell 上,它也始終只獲得相同的 12 個 <@hrefs,并且這是不正常的。我使用這種方式:response.xpath('/html/body/div[1]/div[2]/section/div/div[3]/div[2]/div/div[2]//?div?//article//div[1]// a[re:test(@href,"pd")]//@href').getall()它來自以下頁面:?https://www.lowes.com/pl/Bottom-freezer-refrigerators-Refrigerators-Appliances/4294789499 ?offset=36
查看完整描述

1 回答

?
吃雞游戲

TA貢獻1829條經(jīng)驗 獲得超7個贊

看來html的一部分是動態(tài)加載的,所以scrapy看不到它。數(shù)據(jù)本身存在于 html 中的 json 結(jié)構(gòu)中。你可以嘗試這樣獲?。?/p>


import json

# get the script with the data

json_data = response.xpath('//script[contains(text(), "__PRELOADED_STATE__")]/text()').extract_first()

# load the data in a python dictionary

dict_data = json.loads(json_data.split('window.__PRELOADED_STATE__ =')[-1])

items = dict_data['itemList']

print(len(items))  # prints 36 in my case

# go through the dictionary and get the product_urls

for item in items:

  product_url = item['product']['pdURL']

  ...


查看完整回答
反對 回復(fù) 2023-12-08
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號