from urllib2 import Request, urlopen
from BeautifulSoup import BeautifulSoup
req = Request('http://www.kernel.org/pub/linux/kernel/v3.0/')
response = urlopen(req)
content = response.readlines()
soup = BeautifulSoup(''.join(content))
for link in soup.findAll('a', href=True):
if ('3.6.7.tar.gz' in link.string):
print link
用那个...
>>> from urllib2 import Request, urlopen
>>> from BeautifulSoup import BeautifulSoup
>>> req = Request('http://www.kernel.org/pub/linux/kernel/v3.0/')
>>> response = urlopen(req)
>>> content = response.readlines()
>>> soup = BeautifulSoup(''.join(content))
>>> for link in soup.findAll('a', href=True):
... if ('3.6.7.tar.gz' in link.string):
... print link
...
<a href="linux-3.6.7.tar.gz">linux-3.6.7.tar.gz</a>
>>>
如果要自定义搜索用户输入,请使用 python 的raw_input()
函数...