使用python进行下载地址转换

华军 -> 用户自定义

 

# -*- coding: utf-8 -*- import sys import urllib import string import re url = "http://www.newhua.com/softdown/111369_2.htm" def getHTML(url): return urllib.urlopen(url, ).read(); if __name__ == "__main__": html = getHTML(url); htmls = html.split("/n") page_name = "网点录入信息系统 1.0.6.2 下载"; DL_1 = []; DL_2 = []; DL_3 = []; DL_4 = []; DL_1.append("<dl class=/"unicom/"><dt>联通网通用户通道</dt>"); DL_2.append("<dl class=/"telecom/"><dt>中国电信用户通道</dt>"); DL_3.append("<dl class=/"chinamobile/"><dt>移动铁通用户通道</dt>"); DL_4.append("<dl class=/"other/"><dt>其他网络用户通道</dt>"); for line in htmls: if line.find("durl") < 0: continue; split_line = line.split("'") if len(split_line) > 4: #print "[%s],[%s],[%s]" %(split_line[5],split_line[1],split_line[3]) if split_line[5] == "1": #print '<dd><a href="/" mce_href="/""%s/">%s</a></dd>' %(split_line[3], split_line[1]) DL_1.append("<dd><a href="/" mce_href="/""%s/">%s</a></dd>" %(split_line[3], split_line[1])) elif split_line[5] == "2": DL_2.append("<dd><a href="/" mce_href="/""%s/">%s</a></dd>" %(split_line[3], split_line[1])) elif split_line[5] == "3": DL_3.append("<dd><a href="/" mce_href="/""%s/">%s</a></dd>" %(split_line[3], split_line[1])) elif split_line[5] == "4": DL_4.append("<dd><a href="/" mce_href="/""%s/">%s</a></dd>" %(split_line[3], split_line[1])) DL_1.append("</dl><div class=/"clear/"></div>"); DL_2.append("</dl><div class=/"clear/"></div>"); DL_3.append("</dl><div class=/"clear/"></div>"); DL_4.append("</dl><div class=/"clear/"></div>"); DL = ["<div id=/"url/"><h1>" + page_name + "</h1>"]; DL.append(string.join(DL_2, '')); DL.append(string.join(DL_1, '')); DL.append(string.join(DL_3, '')); DL.append(string.join(DL_4, '')); DL.append("</div>"); page = ''' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Cache-Control" content="no-cache" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="0" /> <title>网点录入信息系统 1.0.5.5 下载</title> <link rel="stylesheet" type="text/css" href="/styles/client/web/download/default.css" mce_href="styles/client/web/download/default.css" /> <mce:style type="text/css"><!-- body{font-size:14px;background:#fff;color:#666;margin:0;padding:0 0 30px;} h1,dl,dt,dd{margin:0;padding:0;} a{color:#666;text-decoration:none;} a:hover{color:red;text-decoration:none;} .clear{clear:both;} #url{width:950px;line-height:30px;margin:30px auto;padding:0 0 10px;} #url h1{font-size:24px;color:#f30;text-align:center;padding:20px 0;} #url dt{background:#f9f9f9;border-top:#ddd solid 1px;font-weight:700;margin:10px auto;padding:0 0 0 10px;} #url dd{width:155px;float:left;padding:0 0 0 35px;} #url dl.telecom dd{background:url(net.gif) no-repeat 10px -54px;} #url dl.other dd{background:url(net.gif) no-repeat 10px 6px;} #url dl.unicom dd{background:url(net.gif) no-repeat 10px -25px;} #url dl.chinamobile dd{background:url(net.gif) no-repeat 10px -85px;} --></mce:style><style type="text/css" mce_bogus="1"> body{font-size:14px;background:#fff;color:#666;margin:0;padding:0 0 30px;} h1,dl,dt,dd{margin:0;padding:0;} a{color:#666;text-decoration:none;} a:hover{color:red;text-decoration:none;} .clear{clear:both;} #url{width:950px;line-height:30px;margin:30px auto;padding:0 0 10px;} #url h1{font-size:24px;color:#f30;text-align:center;padding:20px 0;} #url dt{background:#f9f9f9;border-top:#ddd solid 1px;font-weight:700;margin:10px auto;padding:0 0 0 10px;} #url dd{width:155px;float:left;padding:0 0 0 35px;} #url dl.telecom dd{background:url(net.gif) no-repeat 10px -54px;} #url dl.other dd{background:url(net.gif) no-repeat 10px 6px;} #url dl.unicom dd{background:url(net.gif) no-repeat 10px -25px;} #url dl.chinamobile dd{background:url(net.gif) no-repeat 10px -85px;}</style> </head> <body> <div id="url"> ''' + string.join(DL, '') + '''</div> <!-- Google --> <mce:script type="text/javascript"><!-- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); // --></mce:script> <mce:script type="text/javascript"><!-- try { var pageTracker = _gat._getTracker("UA-548031-10"); pageTracker._setDomainName("none"); pageTracker._setAllowLinker(true); pageTracker._trackPageview(); } catch(err) {} // --></mce:script> <!-- Baidu --> <mce:script type="text/javascript"><!-- var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F829430cfcbb52c9ad7427e83dc8b5630' type='text/javascript'%3E%3C/script%3E")); // --></mce:script> </body> </html> ''' f = open(r'download.html', 'w') f.write(page) f.close() print "python is great!"  

转载于:https://www.cnblogs.com/xingxiudong/archive/2010/12/15/3986989.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值