1.使用beautifulsoup框架。
from bs4 import BeautifulSoupbs = BeautifulSoup('网页源码', "html.parser")
bs.findAll('a') # 查找所有的超链接
# 具体方法可以参见官方文档
2.使用正则表达式
给你贴一下我前一段时间回答的类似问题,用的soup,还有一个用的正则就不贴了,手机不太方便,如下。import beautifulsoup
import urllib2
def main():
userMainUrl = "你要抓取的地址"
req = urllib2.Request(userMainUrl)
resp = urllib2.urlopen(req)
respHtml = resp.read()
foundLabel = respHtml.findAll("label")
finalL =foundLabel.string
print "biaoti=",finalL
if __name__=="__main__":
main()
PS:如果不会改的话追问一下,回头我用电脑给你写一份
假设['/films/1203']是变量list,简单写法是使用+符号,即http...+list[1]。
格式写法是使用format,即str='http...{}'.format(list[1])。