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?
答案 0 :(得分:1)
>>> urlparse.urljoin('http://www.pythonchallenge.com/pc/def/peak.html', 'banner.p')
'http://www.pythonchallenge.com/pc/def/banner.p'