V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
182247236
V2EX  ›  问与答

python 的问题

  •  
  •   182247236 · Oct 20, 2016 · 1719 views
    This topic created in 3479 days ago, the information mentioned may be changed or developed.
    码如下:
    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 replies    2016-10-20 22:55:30 +08:00
    182247236
        1
    182247236  
    OP
       Oct 20, 2016
    我之前是这么写的
    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
       Oct 20, 2016
    要沉吗 TT
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   878 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 22:11 · PVG 06:11 · LAX 15:11 · JFK 18:11
    ♥ Do have faith in what you're doing.