コマンドラインから入力された url を data.html に保存する。
import urllib import sys url = sys.argv[1] filename = "data.html" urllib.urlretrieve(url, filename)
実行結果の data.html(の冒頭部分)
<!DOCTYPE html> <!--[if IE 6]> <html id="ie6" lang="ja"> <![endif]--> <!--[if IE 7]> <html id="ie7" lang="ja"> <![endif]--> <!--[if IE 8]> <html id="ie8" lang="ja"> <![endif]--> <!--[if !(IE 6) | !(IE 7) | !(IE 8) ]><!--> <html lang="ja"> <!--<![endif]--> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width" /> <title>変数に関数と同じ名前をつけてはいけない | blog.PanicBlanket.com</title> <link rel="profile" href="http://gmpg.org/xfn/11" /> <link rel="stylesheet" type="text/css" media="all" href="https://blog.panicblanket.com/wp-content/themes/twentyeleven/style.css" /> <link rel="pingback" href="https://blog.panicblanket.com/xmlrpc.php" /> <!--[if lt IE 9]> <script src="https://blog.panicblanket.com/wp-content/themes/twentyeleven/js/html5.js" type="text/javascript"></script> <![endif]--> <link rel="alternate" type="application/rss+xml" title="blog.PanicBlanket.com » フィード" href="https://blog.panicblanket.com/feed" /> <link rel="alternate" type="application/rss+xml" title="blog.PanicBlanket.com » コメントフィード" href="https://blog.panicblanket.com/comments/feed" /> <link rel="alternate" type="application/rss+xml" title="blog.PanicBlanket.com » 変数に関数と同じ名前をつけてはいけない のコメントのフィード" href="https://blog.panicblanket.com/archives/605/feed" /> <link rel='stylesheet' id='crayon_style-css' href='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/css/crayon_style.css?ver=2.1.1' type='text/css' media='all' /> <link rel='stylesheet' id='crayon_global_style-css' href='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/css/global_style.css?ver=2.1.1' type='text/css' media='all' /> <link rel='stylesheet' id='crayon-theme-classic-css' href='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/themes/classic/classic.css?ver=2.1.1' type='text/css' media='all' /> <link rel='stylesheet' id='crayon-font-monaco-css' href='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/fonts/monaco.css?ver=2.1.1' type='text/css' media='all' /> <link rel='stylesheet' id='wp-syntax-css-css' href='https://blog.panicblanket.com/wp-content/plugins/wp-syntax/wp-syntax.css?ver=3.5.1' type='text/css' media='all' /> <link rel='stylesheet' id='thickbox-css' href='https://blog.panicblanket.com/wp-includes/js/thickbox/thickbox.css?ver=20121105' type='text/css' media='all' /> <link rel='stylesheet' id='amazonjs-css' href='https://blog.panicblanket.com/wp-content/plugins/amazonjs/amazonjs.css?ver=0.1beta3c' type='text/css' media='all' /> <script type='text/javascript' src='https://blog.panicblanket.com/wp-includes/js/jquery/jquery.js?ver=1.8.3'></script> <script type='text/javascript'> /* <![CDATA[ */ var CrayonSyntaxSettings = {"version":"2.1.1","is_admin":"0","ajaxurl":"https:\/\/blog.panicblanket.com\/wp-admin\/admin-ajax.php","prefix":"crayon-","setting":"crayon-setting","selected":"crayon-setting-selected","changed":"crayon-setting-changed","special":"crayon-setting-special","orig_value":"data-orig-value","debug":""}; var CrayonSyntaxStrings = {"copy":"\u8cbc\u308a\u4ed8\u3051\u306b\u30b3\u30d4\u30fc\u3001%s\u306b%s\u3092\u62bc\u3057\u3066\u3001","minimize":"Click To Expand Code"}; /* ]]> */ </script> <script type='text/javascript' src='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/js/util.js?ver=2.1.1'></script> <script type='text/javascript' src='https://blog.panicblanket.com/wp-content/plugins/crayon-syntax-highlighter/js/crayon.js?ver=2.1.1'></script> <script type='text/javascript' src='https://blog.panicblanket.com/wp-includes/js/comment-reply.min.js?ver=3.5.1'></script> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://blog.panicblanket.com/xmlrpc.php?rsd" /> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://blog.panicblanket.com/wp-includes/wlwmanifest.xml" /> <link rel='prev' title='== 演算子と is 演算子' href='https://blog.panicblanket.com/archives/600' /> <meta name="generator" content="WordPress 3.5.1" /> <link rel='canonical' href='https://blog.panicblanket.com/archives/605' /> <link rel='shortlink' href='https://blog.panicblanket.com/?p=605' /> <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> <style type="text/css" id="custom-background-css"> body.custom-background { background-color: #e2e2e2; } </style> </head>