鱼C论坛

 找回密码
 立即注册
查看: 570|回复: 2

[已解决]求怎样获取网页中的信息

[复制链接]
发表于 2020-5-24 06:12:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请问各位鱼油们怎样获取网页中的信息呢
由于无权发送图片,我决定把网页内容复制过来
({"singer":[{"gsid":"67087","singer":"\u8521\u5f90\u5764","gspic":"http:\/\/aliyunimg.9ku.com\/9kuimg\/geshou\/20180320\/ffdec79af504b516.jpg?x-oss-process=image\/resize,m_fill,w_150,h_150,limit_0\/auto-orient,0"}],
"music":[{"id":"998960","mname":"\u91cd\u751f","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"886000","mname":"\u6ca1\u6709\u610f\u5916","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"877020","mname":"I Wanna Get Love","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881707","mname":"Wait Wait Wait","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003660","mname":"Home","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003003","mname":"\u5c71\u6cb3\u65e0\u6059\u5728\u6211\u80f8","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"890578","mname":"Hard To Get","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"888794","mname":"Bigger","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881332","mname":"You Can Be My GirlFriend","gsid":"67087","singer":"\u8521\u5f90\u5764"}],
"so":["\u8521\u5f90\u5764","vitas","star","\u561f\u554a\u561f\u554a","\u6d3b\u51fa\u57fa\u7763\u6b4c","\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60","\u535c\u5366","\u7231\u60c5\u4e70\u5356","\u4e16\u754c\u7b2c\u4e00\u7b49","\u542c\u5988\u5988\u7684\u8bdd","\u51b0\u6cb3\u65f6\u4ee3"]})
各位鱼油们,怎么获取所有的“id”值?
最佳答案
2020-5-24 07:20:03
本帖最后由 Twilight6 于 2020-5-24 07:31 编辑

用正则即可:
import re

str1 = r"""
({"singer":[{"gsid":"67087","singer":"\u8521\u5f90\u5764","gspic":"http:\/\/aliyunimg.9ku.com\/9kuimg\/geshou\/20180320\/ffdec79af504b516.jpg?x-oss-process=image\/resize,m_fill,w_150,h_150,limit_0\/auto-orient,0"}],
"music":[{"id":"998960","mname":"\u91cd\u751f","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"886000","mname":"\u6ca1\u6709\u610f\u5916","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"877020","mname":"I Wanna Get Love","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881707","mname":"Wait Wait Wait","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003660","mname":"Home","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003003","mname":"\u5c71\u6cb3\u65e0\u6059\u5728\u6211\u80f8","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"890578","mname":"Hard To Get","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"888794","mname":"Bigger","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881332","mname":"You Can Be My GirlFriend","gsid":"67087","singer":"\u8521\u5f90\u5764"}],
"so":["\u8521\u5f90\u5764","vitas","star","\u561f\u554a\u561f\u554a","\u6d3b\u51fa\u57fa\u7763\u6b4c","\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60","\u535c\u5366","\u7231\u60c5\u4e70\u5356","\u4e16\u754c\u7b2c\u4e00\u7b49","\u542c\u5988\u5988\u7684\u8bdd","\u51b0\u6cb3\u65f6\u4ee3"]})
"""

id = re.findall(r'"id":"(.+?)"',str1)
print(id)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-5-24 07:20:03 | 显示全部楼层    本楼为最佳答案   
本帖最后由 Twilight6 于 2020-5-24 07:31 编辑

用正则即可:
import re

str1 = r"""
({"singer":[{"gsid":"67087","singer":"\u8521\u5f90\u5764","gspic":"http:\/\/aliyunimg.9ku.com\/9kuimg\/geshou\/20180320\/ffdec79af504b516.jpg?x-oss-process=image\/resize,m_fill,w_150,h_150,limit_0\/auto-orient,0"}],
"music":[{"id":"998960","mname":"\u91cd\u751f","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"886000","mname":"\u6ca1\u6709\u610f\u5916","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"877020","mname":"I Wanna Get Love","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881707","mname":"Wait Wait Wait","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003660","mname":"Home","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"1003003","mname":"\u5c71\u6cb3\u65e0\u6059\u5728\u6211\u80f8","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"890578","mname":"Hard To Get","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"888794","mname":"Bigger","gsid":"67087","singer":"\u8521\u5f90\u5764"},
{"id":"881332","mname":"You Can Be My GirlFriend","gsid":"67087","singer":"\u8521\u5f90\u5764"}],
"so":["\u8521\u5f90\u5764","vitas","star","\u561f\u554a\u561f\u554a","\u6d3b\u51fa\u57fa\u7763\u6b4c","\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60","\u535c\u5366","\u7231\u60c5\u4e70\u5356","\u4e16\u754c\u7b2c\u4e00\u7b49","\u542c\u5988\u5988\u7684\u8bdd","\u51b0\u6cb3\u65f6\u4ee3"]})
"""

id = re.findall(r'"id":"(.+?)"',str1)
print(id)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-5-24 07:57:18 | 显示全部楼层
用json简白明了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-21 02:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表