scrapy返回的response为str对象,如何转换成response提取目标值?

通过抓取,最后返回的对象为以下内容,发现对象属性为string,现在应该如何提取?

{"r":0, "msg": ["<div class="item"><div class="blk">
<a target="_blank" href="/topic/19564906">
<img src="https://pic2.zhimg.com/35acee23dc6b42ee9abead8f2d00c9a5_xs.jpg" alt="Android u6e38u620f">
<strong>Android u6e38u620f</strong>
</a>
<p></p> <a id="t::-4897" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19568806">
<img src="https://pic4.zhimg.com/23c6509df_xs.jpg" alt="Unityuff08u6e38u620fu5f15u64ceuff09">
<strong>Unityuff08u6e38u620fu5f15u64ceuff09</strong>
</a>
<p>Unity u662fu4e00u79cdu96c6u6210u7684u521bu4f5cu5de5u5177uff0cu9488u5bf93Du6e38u620fu548cu5176u4ed6u4ea4u4e92u5185u5bb9uff08u2026</p> <a id="t::-6199" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19552038">
<img src="https://pic2.zhimg.com/bec983801_xs.jpg" alt="u76dbu5927u7f51u7edc">
<strong>u76dbu5927u7f51u7edc</strong>
</a>
<p>u4e0au6d77u76dbu5927u7f51u7edcu53d1u5c55u6709u9650u516cu53f8uff08u7b80u79f0u201cu76dbu5927u7f51u7edcu201duff09u662fu4e2du56fdu7684u7f51u7edcu6e38u620fu8fd0u2026</p> <a id="t::-611" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19583842">
<img src="https://pic3.zhimg.com/097b126eebd99490cdab183c0389b30e_xs.jpg" alt="u72ecu7acbu6e38u620f">
<strong>u72ecu7acbu6e38u620f</strong>
</a>
<p>u72ecu7acbu6e38u620fu6307u6e38u620fu5f00u53d1u8005u6ca1u6709u6e38u620fu516cu53f8u6216u6e38u620fu53d1u884cu5546u63d0u4f9bu7684u85aau8d44uff0cu5fc5u987bu72ecu2026</p> <a id="t::-11190" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19590019">
<img src="https://pic2.zhimg.com/8ef8852e1_xs.jpg" alt="u6865u724c">
<strong>u6865u724c</strong>
</a>
<p>u7231u597du8005u904du53cau5168u4e16u754cu7684u4e00u79cdu6251u514bu6e38u620fuff0cu4e16u754cu8303u56f4u3001u6d32u9645u8303u56f4u90fdu8bbeu6709u6865u724cu534fu2026</p> <a id="t::-13245" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19600554">
<img src="https://pic1.zhimg.com/bb3b26f06cf1339294eb24761761f364_xs.jpg" alt="u6e38u620fu4ea7u4e1a">
<strong>u6e38u620fu4ea7u4e1a</strong>
</a>
<p></p> <a id="t::-16821" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19550880">
<img src="https://pic4.zhimg.com/ae43a82db_xs.jpg" alt="u827au7535 EA">
<strong>u827au7535 EA</strong>
</a>
<p>u7f8eu56fdu827au7535u662fu5168u7403u8457u540du7684u4e92u52a8u5a31u4e50u8f6fu4ef6u5236u4f5cu4e0eu53d1u884cu516cu53f8uff0cu603bu90e8u4f4du4e8eu7f8eu56fdu52a0u2026</p> <a id="t::-218" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19632659">
<img src="https://pic3.zhimg.com/9ab3edd2b3164d91de0099b2282bbd4a_xs.jpg" alt="u523au5ba2u4fe1u6761uff08Assassins Creeduff09">
<strong>u523au5ba2u4fe1u6761uff08Assassins Creeduff09</strong>
</a>
<p>u2014u2014u613fu6d1eu5bdfu4e4bu7236u6307u5f15u6211u7b49u3002 u4e07u7269u7686u865auff0cu4e07u4e8bu7686u5141u3002 u8fd9u662fu6211u4eecu7684u7956u5148u2026</p> <a id="t::-27576" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19660478">
<img src="https://pic1.zhimg.com/922bbf820_xs.jpg" alt="u6587u660euff08u7cfbu5217u6e38u620fuff09">
<strong>u6587u660euff08u7cfbu5217u6e38u620fuff09</strong>
</a>
<p>u300au6587u660eu300bu6700u65e9u7531u72ecu7acbu5f00u53d1u8005u5f00u53d1uff0cu540eu7ecfMicroproseuff0cu518du5230Fu2026</p> <a id="t::-36841" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19553255">
<img src="https://pic3.zhimg.com/4b784a796_xs.jpg" alt="Xbox">
<strong>Xbox</strong>
</a>
<p>Xbox u662fu5faeu8f6fu6240u5f00u53d1u3001u9500u552eu7684u5bb6u7528u6e38u620fu4e3bu673au3002</p> <a id="t::-1015" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19552479">
<img src="https://pic4.zhimg.com/aea34d9b3_xs.jpg" alt="u661fu9645u4e89u9738">
<strong>u661fu9645u4e89u9738</strong>
</a>
<p>u300au661fu9645u4e89u9738u300bu662fu7531u66b4u96eau5a31u4e50u5236u4f5cu53d1u884cu7684u4e00u6b3eu8457u540du5373u65f6u6218u7565u6e38u620fu3002u8fd9u662fu661fu2026</p> <a id="t::-757" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19625841">
<img src="https://pic4.zhimg.com/8d6a36a3f_xs.jpg" alt="Cocos2d-x">
<strong>Cocos2d-x</strong>
</a>
<p>Cocos2d-xu662fu4e00u4e2au5f00u6e90u7684u79fbu52a82Duff08u76eeu524du5df2u7ecfu67093Du7248u672cuff09u6e38u2026</p> <a id="t::-25295" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19839210">
<img src="https://pic1.zhimg.com/47206e784_xs.jpg" alt="u7cbeu7075u5b9du53efu68a6uff08Poku00e9monuff09">
<strong>u7cbeu7075u5b9du53efu68a6uff08Poku00e9monuff09</strong>
</a>
<p>u7cbeu7075u5b9du53efu68a6u7cfbu5217uff08Poku00e9monuff0cu30ddu30b1u30c3u30c8u30e2u30f3u30b9u30bfu30fcuff09uff0cu53c8u79f0u53e3u888bu2026</p> <a id="t::-98461" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19785574">
<img src="https://pic3.zhimg.com/ae975386a_xs.jpg" alt="Ingressuff08u589eu5f3au73b0u5b9eu6e38u620fuff09">
<strong>Ingressuff08u589eu5f3au73b0u5b9eu6e38u620fuff09</strong>
</a>
<p>Ingress u662fu4e00u6b3eu4fb5u5165u5f0fu865au62dfu73b0u5b9eu6e38u620fu3001u5927u578bu591au4ebau7535u5b50u6e38u620fuff0cu4e2du2026</p> <a id="t::-78940" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19670052">
<img src="https://pic2.zhimg.com/24e0bcc51_xs.jpg" alt="u6881u6b22">
<strong>u6881u6b22</strong>
</a>
<p>u6881u6b22 </p> <a id="t::-40034" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19558999">
<img src="https://pic3.zhimg.com/05912f7847b0654a695c8bc68d348ba2_xs.jpg" alt="u7b2cu4e00u4ebau79f0u89c6u89d2u5c04u51fbu6e38u620fuff08FPSuff09">
<strong>u7b2cu4e00u4ebau79f0u89c6u89d2u5c04u51fbu6e38u620fuff08FPSuff09</strong>
</a>
<p>u7b2cu4e00u4ebau79f0u5c04u51fbuff08First-person shooteruff09u6e38u620fu662fu2026</p> <a id="t::-2937" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19552043">
<img src="https://pic1.zhimg.com/df7985174_xs.jpg" alt="u76dbu5927u521bu65b0u9662">
<strong>u76dbu5927u521bu65b0u9662</strong>
</a>
<p></p> <a id="t::-612" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19556258">
<img src="https://pic3.zhimg.com/389f27418bb3b6e5baddb06b00d98f36_xs.jpg" alt="u6e38u620fu5f15u64ce">
<strong>u6e38u620fu5f15u64ce</strong>
</a>
<p></p> <a id="t::-2000" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19554169">
<img src="https://pic4.zhimg.com/d74afc7906aa5209503de78978777997_xs.jpg" alt="u7535u5b50u6e38u620f">
<strong>u7535u5b50u6e38u620f</strong>
</a>
<p></p> <a id="t::-1314" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>","<div class="item"><div class="blk">
<a target="_blank" href="/topic/19564209">
<img src="https://pic3.zhimg.com/d3f7f95975ae3ff5cfeedad9a4febe56_xs.jpg" alt="u6e38u620fu754cu9762u8bbeu8ba1">
<strong>u6e38u620fu754cu9762u8bbeu8ba1</strong>
</a>
<p></p> <a id="t::-4657" href="javascript:;" class="follow meta-item zg-follow"><i class="z-icon-follow"></i>u5173u6ce8</a> </div></div>"]
}

<type str>

如何转换为response对象,然后提取中间的目标值?

这是JSON,转化一下:

import json content = ...你那堆东西
result = json.loadscontent print result[msg]

这样就把你获取的JSON格式字符串转化成了result字典,然后再正常处理就好了。

返回的是json数据数据,用python的json库直接解析。
我感觉爬到json数据处理起来最爽了,
最近爬的很多都是后续请求生成的 json数据

发表评论

电子邮件地址不会被公开。 必填项已用*标注