V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
182247236
V2EX  ›  问与答

python 的问题

  •  
  •   182247236 · 2016-10-20 18:02:34 +08:00 · 1134 次点击
    这是一个创建于 2717 天前的主题,其中的信息可能已经有所发展或是发生改变。
    码如下:
    PID = 'lKGXIQa'

    GetPlayer = "http://213432.com/liveforapp.php?cid={cid}&appid={appid}" .format(cid=PID,appid="01")

    from urllib.request import urlopen
    from pprint import pprint
    from bs4 import BeautifulSoup

    url = urlopen(GetPlayer)
    print(url.read())
    这样我就能得出
    b'<a href="http://213432.com/live.php?token=dH0xNDc2XTU3NDc2JmM9bEtHWElRYSZhPTAxJnY9ZWJhZGY|">http://213432com/live.php?token=dH0xNDc2XTU3NDc2JmM9bEtHWElRYSZhPTAxJnY9ZWJhZGY|</a>'
    问题是我只想得出 url ,因为待会要用...html 标签什么的没用,网上查了查好多没用的资料 TT ,有什么办法吗?
    2 条回复    2016-10-20 22:55:30 +08:00
    182247236
        1
    182247236  
    OP
       2016-10-20 18:04:54 +08:00
    我之前是这么写的
    PID = 'lKGXIQa'

    GetPlayer = "http://12345.cutv.com/liveforapp.php?cid=%s" %PID +'&appid=S01'

    from urllib.request import urlopen
    from pprint import pprint
    from bs4 import BeautifulSoup



    html = urlopen(GetPlayer)

    bs_obj = BeautifulSoup(html,'html.parser')

    for link in bs_obj.findAll('a'):
    print(link.get_text())
    这么可以得出我需要的 url ,可是我觉得太复杂不好,想改简单点
    182247236
        2
    182247236  
    OP
       2016-10-20 22:55:30 +08:00
    要沉吗 TT
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3394 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 10:41 · PVG 18:41 · LAX 03:41 · JFK 06:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.