Python相当于浏览器中的“复制链接位置”

时间:2012-09-25 14:53:39

标签: python file url

www.pythonchallenge.com/pc/def/peak.html的来源如下:

<html>
<head>
  <title>peak hell</title>
  <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<center>
<img src="peakhell.jpg"/>
<br><font color="#c0c0ff">
pronounce it
<br>
<peakhell src="banner.p"/>
</body>
</html>

<!-- peak hell sounds familiar ? -->

我可以通过右键单击www.pythonchallenge.com/pc/def/banner.p并在Firefox中选择banner.p来获取网址(copy link location)。如何只使用Python获取此URL?

1 个答案:

答案 0 :(得分:1)

>>> urlparse.urljoin('http://www.pythonchallenge.com/pc/def/peak.html', 'banner.p')
'http://www.pythonchallenge.com/pc/def/banner.p'