python 爬虫(一) requests库

1.下载requests 库

pip install requests

2.请求url

import requests

url = 'https://www.baidu.com' #要爬取的url 这里拿百度官网测试

res = requests.get(url) #请求url

print(res) #输出请求

这时运行以上的代码,就会得到以下输出:

<Response [200]>

这是返回值的状态码,在后面+text来读取返回的内容

import requests

url = 'https://www.baidu.com' #要爬取的url

res = requests.get(url) #请求url

print(res.text) #输出请求

输出:

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.min.css><title>ç¾åº¦ä¸ä¸ï¼ä½ å°±çé</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div cl
ass=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input 
type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus=autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=ç¾åº¦ä¸ä¸ class="bg s_btn" autofocus></span> </form> </div> </div> <div id=u1> <a href=http://n
ews.baidu.com name=tj_trnews class=mnav>æ°é»</a> <a href=https://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.ba
idu.com name=tj_trmap class=mnav>å°å</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>è§é¢</a> <a href=http://tieba.baidu.com name
=tj_trtieba class=mnav>è´´å</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f
%3fbdorz_come%3d1 name=tj_login class=lb>ç»å½</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tp
l=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">ç»å½</a>');
                </script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">æå¤äº§å</a> </div> </div> </div> 
<div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>å
³äºç¾åº¦</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id
=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使ç¨ç¾åº¦åå¿
读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-fe
edback>æ
        è§åé¦</a>&nbsp;京ICPè¯030173å·&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

然后我们会发现,输出的都是一些乱七八糟的东西,还有看不懂的乱码这是因为访问网站需要特定的请求头(headers),因为没有请求头,网站发现我们是爬虫,就会把我们禁止访问。。。

import requests

url = 'https://www.baidu.com' #要爬取的url

headers = {   #添加请求头
    ''
}

res = requests.get(url) #请求url

print(res.text) #输出请求

现在,右键屏幕,点击审查元素,点开网络(Networks),在下面会看到一些数据,如下

点进去之后,在标头中往下滑,找到User Agent

复制下来,粘贴进headers里面,这就是我们的用来伪装自己成人类的信息,如下:

import requests

url = 'https://www.baidu.com' #要爬取的url

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36'
}

res = requests.get(url) #请求url
print(res.text)

现在再运行这行代码,就会发现,输出的内容变多了,如下就是百度官网的源代码

<!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta content="always" name="referrer"><meta name="theme-color" content="#ffffff"><meta name="description" content="全球领先的中文搜索引擎、致力于让网民更便捷地获取信息,找到所求。百度超过千亿的中文网页数据库,可以瞬间找到相关的搜索结果。"><link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon" /><link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" /><link rel="stylesheet" data-for="result" href="https://pss.bdstatic.com/r/www/static/font/cosmic/pc/cos-icon_99f656e.css"/><link rel="icon" sizes="any" mask href="https://www.baidu.com/favicon.ico"><link rel="dns-prefetch" href="//dss0.bdstatic.com"/><link rel="dns-prefetch" href="//dss1.bdstatic.com"/><link rel="dns-prefetch" href="//ss1.bdstatic.com"/><link rel="dns-prefetch" href="//sp0.baidu.com"/><link rel="dns-prefetch" href="//sp1.baidu.com"/><link rel="dns-prefetch" href="//sp2.baidu.com"/><link rel="dns-prefetch" href="//pss.bdstatic.com"/><link rel="apple-touch-icon-precomposed" href="https://psstatic.cdn.bcebos.com/video/wiseindex/aa6eef91f8b5b1a33b454c401_1660835115000.png"><title>百度一下,你就知道</title><style index="newi" type="text/css">#form .bdsug{top:39px}.bdsug{display:none;position:absolute;width:535px;background:#fff;border:1px solid #ccc!important;_overflow:hidden;box-shadow:1px 1px 3px #ededed;-webkit-box-shadow:1px 1px 3px #ededed;-moz-box-shadow:1px 1px 3px #ededed;-o-box-shadow:1px 1px 3px #ededed}.bdsug li{width:519px;color:#000;font:14px arial;line-height:25px;padding:0 8px;position:relative;cursor:default}.bdsug li.bdsug-s{background:#f0f0f0}.bdsug-store span,.bdsug-store b{color:#7A77C8}.bdsug-store-del{font-size:12px;color:#666;text-decoration:underline;position:absolute;right:8px;top:0;cursor:pointer;display:none}.bdsug-s .bdsug-store-del{display:inline-block}.bdsug-ala{display:inline-block;border-bottom:1px solid #e6e6e6}.bdsug-ala h3{line-height:14px;background:url(//www.baidu.com/img/sug_bd.png?v=09816787.png) no-repeat left center;margin:6px 0 4px;font-size:12px;font-weight:400;color:#7B7B7B;padding-left:20px}.bdsug-ala p{font-size:14px;font-weight:700;padding-left:20px}#m .bdsug .bdsug-direct p{color:#00c;font-weight:700;line-height:34px;padding:0 8px;margin-top:0;cursor:pointer;white-space:nowrap;overflow:hidden}#m .bdsug .bdsug-direct p img{width:16px;height:16px;margin:7px 6px 9px 0;vertical-align:middle}#m .bdsug .bdsug-direct p span{margin-left:8px}#form .bdsug .bdsug-direct{width:auto;padding:0;border-bottom:1px solid #f1f1f1}#form .bdsug .bdsug-direct p i{font-size:12px;line-height:100%;font-style:normal;font-weight:400;color:#fff;background-color:#2b99ff;display:inline;text-align:center;padding:1px 5px;*padding:2px 5px 0;margin-left:8px;overflow:hidden}.bdsug .bdsug-pcDirect{color:#000;font-size:14px;line-height:30px;height:30px;background-color:#f8f8f8}.bdsug .bdsug-pc-direct-tip{position:absolute;right:15px;top:8px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc_direct_42d6311.png) no-repeat 0 0}.bdsug li.bdsug-pcDirect-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-is{color:#000;font-size:14px;line-height:22px;background-color:#f5f5f5}.bdsug .bdsug-pc-direct-tip-is{position:absolute;right:15px;top:3px;width:55px;height:15px;display:block;background:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/global/img/pc_direct_42d6311.png) no-repeat 0 0}.bdsug li.bdsug-pcDirect-is-s{background-color:#f0f0f0}.bdsug .bdsug-pcDirect-s .bdsug-pc-direct-tip,.bdsug .bdsug-pcDirect-is-s .bdsug-pc-direct-tip-is{background-position:0 -15px}.bdsug .bdsug-newicon{color:#929292;opacity:.7;font-size:12px;display:inline-block;line-height:22px;letter-spacing:2px}.bdsug .bdsug-s .bdsug-newicon{opacity:1}.bdsug .bdsug-newicon i{letter-spacing:0;font-style:normal}.bdsug .bdsug-feedback-wrap{display:none}.toggle-underline{text-decoration:none}.toggle-underline:hover{text-decoration:underline}.bdpfmenu,.usermenu{border:1px solid #d1d1d1;position:absolute;width:105px;top:36px;z-index:302;box-shadow:1px 1px 5px #d1d1d1;-webkit-box-shadow:1px 1px 5px #d1d1d1;-moz-box-shadow:1px 1px 5px #d1d1d1;-o-box-shadow:1px 1px 5px #d1d1d1}.bdpfmenu{font-size:12px;background-color:#fff}.bdpfmenu a,.usermenu a{display:block;text-align:left;margin:0!important;padding:0 9px;line-height:26px;text-decoration:none}.briiconsbg{background-repeat:no-repeat;background-size:300px 18px;background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/home/img/icons_0c37e9b.png);background-image:url(https://pss.bdstatic.com/r/www/cache/static/protocol/https/home/img/icons_809ae65.gif)\9}.bdpfmenu a:link,.bdpfmenu a:visited,#u .usermenu a:link,#u .usermenu a:visited{background:#fff;color:#333}.bdpfmenu a:hover,.bdpfmenu a:active,#u .usermenu a:hover,#u .usermenu a:active{background:#38f;text-decoration:none;color:#fff}.bdpfmenu{width:70px}#wrapper .bdnuarrow{width:0;height:0;font-size:0;line-height:0;display:block;position:absolute;top:-10px;left:50%;margin-left:-5px}#wrapper .bdnuarrow em,#wrapper .bdnuarrow i{width:0;height:0;font-size:0;line-height:0;display:block;position:absolute;border:5px solid transparent;border-style:dashed dashed solid}#wrapper .bdnuarrow em{border-bottom-color:#d8d8d8;top:-1px}#wrapper .bdnuarrow i{border-bottom-color:#fff;top:0}#gxszHead .prefpanelclose{cursor:pointer;width:16px;height:16px;float:right;margin-top:7px;background-position:-248px 0}#gxszHead .prefpanelclose:hover{background-position:-264px 0}.s_ipt::-webkit-input-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt::-moz-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt:-ms-input-placeholder{padding-left:3px;color:#aaa;font-size:13px}.s_ipt::placeholder{padding-left:3px;color:#aaa;font-size:13px}.kw-placeholder{position:absolute;top:0;left:0;color:#aaa;font-size:13px;height:40px;line-height:40px;padding-left:10px;max-width:360px;z-index:99;pointer-events:none}.kw-placeholder.kw-placehlder-high{height:40px;line-height:40px}.kw-placeholder.placeholders-hidden{visibility:hidden}#head_wrapper #form .bdsug-new{width:544px;top:35px;border-radius:0 0 10px 10px;border:2px solid #4E6EF2!important;border-top:0!important;box-shadow:none;font-family:Arial,sans-serif;z-index:1}#head_wrapper.sam_head_wrapper2 #form .bdsug-new{width:545px;z-index:1;border:1px solid #4E6EF2!important;border-top:0!important}#head_wrapper #form .bdsug-new ul{margin:7px 14px 0;padding:8px 0 7px;background:0 0;border-top:2px solid #f5f5f6}#head_wrapper #form .bdsug-new ul li{position:relative;width:auto;padding-left:14px;margin-left:-14px;margin-right:-14px;color:#626675;line-height:28px;background:0 0;font-family:Arial,sans-serif}#head_wrapper #form .bdsug-new ul li .sug-search-icon,#head_wrapper #form .bdsug-new ul li .sug-history-icon{margin-right:4px;color:#222}#head_wrapper #form .bdsug-new ul li span{color:#626675}#head_wrapper #form .bdsug-new ul li b{font-weight:400;color:#222}#head_wrapper #form .bdsug-new .bdsug-store-del{font-size:13px;text-decoration:none;color:#9195A3;right:16px}#head_wrapper #form .bdsug-new .bdsug-store-del:hover{color:#315EFB;cursor:pointer}#head_wrapper #form .bdsug-new ul li:hover,#head_wrapper #form .bdsug-new ul li:hover span,#head_wrapper #form .bdsug-new ul li:hover b{cursor:pointer}.wrapper_new #form .bdsug-new .bdsug-s{background-color:#F5F5F6!important}.wrapper_new #form .sam_search .bdsug-new .bdsug-s{background-color:#F1F3FD!important}#head_wrapper #form .sam_search .bdsug-new .bdsug-s{background-color:#F1F3FD!important}#head .s-down #form .bdsug-new{top:32px}.s-skin-hasbg #head_wrapper #form .bdsug-new{border-color:#4569ff!important;border-top:0!important}.s-skin-hasbg #head_wrapper.s-down #form .bdsug-new{border-color:#4e6ef2!important;border-top:0!important}.s-skin-hasbg #head_wrapper.s-down #form.sam_search .bdsug-new{border-color:rgba(0,0,0,.05)!important;border-top:1px solid rgba(0,0,0,.05)!important;top:54px!important}#head_wrapper #form .bdsug-new .bdsug-s,#head_wrapper #form .bdsug-new .bdsug-s span,#head_wrapper #form .bdsug-new .bdsug-s b{color:#315EFB}#head_wrapper #form .bdsug-new>div span:hover,#head_wrapper #form .bdsug-new>div a:hover{color:#315EFB!important}#head_wrapper #form #kw.new-ipt-focus{border-color:#4e6ef2}#head_wrapper #form .bdsug-new ul li{}#head_wrapper #form .bdsug-new ul li .sug-hot-orange,#head_wrapper #form .bdsug-new ul li .sug-hot-grey,#head_wrapper #form .bdsug-new ul li .sug-hot-blue{display:inline-block;width:12px;height:12px;font-size:12px;line-height:12px;padding:2px;text-align:center;font-weight:500;margin-left:6px;vertical-align:text-bottom}#head_wrapper #form .bdsug-new ul li .sug-hot-orange{display:inline-block;color:#fff;background:#F60;border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag{text-align:center;margin-left:6px;box-sizing:border-box;font-size:12px;line-height:14px;padding:1px 4px;font-weight:500}#head_wrapper #form .bdsug-new ul li .sug-new-tag-grey{color:#858585;border:1px solid rgba(133,133,133,.5);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag-blue{color:#36F;border:1px solid rgba(51,102,255,.4);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-new-tag-orange{color:#F33;border:1px solid rgba(255,51,51,.4);border-radius:4px}#head_wrapper #form .bdsug-new ul li .sug-tag-text{position:sticky;right:-4px;margin-top:-2px;display:inline-block;box-sizing:border-box;margin-left:6px;padding:1px;font-size:12px;line-height:12px;font-weight:500;text-align:center;border-radius:4px;vertical-align:middle;border-width:1px;border-style:solid}#head_wrapper #form .bdsug-new ul li .sug-tag-img{height:18px;max-width:80px;vertical-align:middle;margin-left:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap{display:block;height:40px;padding:7px 0;color:#222}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap:visited{color:#222}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img-wrap{position:relative}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img-wrap::before{content:"";width:38px;height:38px;position:absolute;top:0;right:0;left:0;bottom:0;border:1px solid rgba(0,0,0,.06);border-radius:9px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .left-img{box-sizing:border-box;float:left;width:40px;height:40px;border:1px solid rgba(0,0,0,.06);border-radius:9px;margin-right:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .content{float:left}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .header{margin-bottom:6px;line-height:18px;height:18px;vertical-align:middle}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .name{float:left;font-size:16px;color:#222;font-weight:500}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .tag-img{width:18px;margin-left:4px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .more{line-height:14px;width:240px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .brief,#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .info{font-size:14px;color:#222;font-weight:400}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .brief{margin-right:6px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .right-btn{float:right;margin-top:5px;margin-right:6px;width:60px;height:24px;text-align:center;font-size:14px;color:#36F;line-height:24px;background-image:linear-gradient(111deg,#e8f7ff 0,#edf0ff 100%);border-radius:12px}#head_wrapper #form .bdsug-new ul li .direct-sug-wrap .right-btn:hover{background:#315efb;color:#fff}#head_wrapper #form .bdsug-new ul li:hover .direct-sug-wrap .name{color:#315EFB}#head_wrapper #form .bdsug-new ul li:hover .direct-sug-wrap .brief{color:#222}#head_wrapper.s-down #form .sam-bdsug.bdsug-new{top:52px}#head_wrapper #form .sam-bdsug.bdsug-new{width:100%;box-shadow:0 4px 4px 0 rgba(0,0,0,.1);border:1px solid rgba(0,0,0,.05)!important;border-radius:12px;top:56px}#head_wrapper #form .sam-bdsug.bdsug-new ul{border:0;padding:0 0 7px}#head_wrapper #form .sam-bdsug.bdsug-new ul li{line-height:32px}#head_wrapper #form .sam-bdsug.bdsug-new ul .bdsug-s{background-color:#F1F3FD!important}#head_wrapper #form .sam-bdsug.bdsug-new .bdsug-store-del{right:15px}.sam_search .sam_search_rec,.sam_search .sam_search_soutu{z-index:1;display:none;position:absolute;top:50%;margin-top:-12px;font-size:24px;color:#4E6EF2;height:24px;line-height:24px;width:24px;cursor:pointer;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);transition:transform .3s ease}.sam_search .sam_search_rec{right:54px}.sam_search .sam_search_soutu{right:14px}.sam_search .sam_search_rec:hover,.sam_search .sam_search_soutu:hover{color:#1D4FFF!important;transform:scale(1.08,1.08)}.sam_search .sam_search_rec_hover,.sam_search .sam_search_soutu_hover{background:#626675;border-radius:8px;height:32px;width:76px;text-align:center;line-height:32px;font-size:13px;color:#FFF;position:absolute;z-index:2;top:50px}.sam_search .sam_search_rec_hover:before,.sam_search .sam_search_soutu_hover:before{content:'';border:4px solid transparent;border-bottom:4px solid #626675;position:absolute;left:50%;top:-8px;margin-left:-4px}.sam_search .sam_search_rec_hover{right:29px}.sam_search .sam_search_soutu_hover{display:none;right:-12px}</style><style type="text/css" index="superbase">blockquote,body,button,dd,dl,dt,fieldset,form,h1,h2,h3,h4,h5,h6,hr,input,legend,li,ol,p,pre,td,textarea,th,ul{margin:0;padding:0}
html{color:#000;overflow-y:scroll;overflow:-moz-scrollbars}
body,button,input,select,textarea{font-size:12px;font-family:Arial,sans-serif}
h1,h2,h3,h4,h5,h6{font-size:100%}
em{font-style:normal}
small{font-size:12px}
ol,ul{list-style:none}
a{text-decoration:none}
a:hover{text-decoration:underline}
legend{color:#000}
fieldset,img{border:0}
button,input,select,textarea{font-size:100%}
table{border-collapse:collapse;border-spacing:0}
img{-ms-interpolation-mode:bicubic}
textarea{resize:vertical}
.left{float:left}
.right{float:right}
.overflow{overflow:hidden}
.hide{display:none}
.block{display:block}
.inline{display:inline}
.error{color:red;font-size:12px}
button,label{cursor:pointer}
.clearfix:after{content:'\20';display:block;height:0;clear:both}
.clearfix{zoom:1}
.clear{clear:both;height:0;line-height:0;font-size:0;visibility:hidden;overflow:hidden}
.wordwrap{word-break:break-all;word-wrap:break-word}
.s-yahei{font-family:arial,'Microsoft Yahei','微软雅黑'}
pre.wordwrap{white-space:pre-wrap}
body{text-align:center;background:#fff;width:100%}
body,form{position:relative;z-index:0}
td{text-align:left}
img{border:0}
#s_wrap{position:relative;z-index:0;min-width:1000px}
#wrapper{height:100%}
#head .s-ps-islite{_padding-bottom:370px}
#head_wrapper.s-ps-islite{padding-bottom:370px}
#head_wrapper.s-ps-islite #s_lm_wrap{bottom:298px;background:0 0!important;filter:none!important}
#head_wrapper.s-ps-islite .s_form{position:relative;z-index:1}
#head_wrapper.s-ps-islite .fm{position:absolute;bottom:0}
#head_wrapper.s-ps-islite .s-p-top{position:absolute;bottom:40px;width:100%;height:181px}
#head_wrapper.s-ps-islite #s_lg_img,#head_wrapper.s-ps-islite #s_lg_img_aging,#head_wrapper.s-ps-islite #s_lg_img_new{position:static;margin:33px auto 0 auto}
.s_lm_hide{display:none!important}
#head_wrapper.s-down #s_lm_wrap{display:none}
.s-lite-version #m{padding-top:125px}
#s_lg_img,#s_lg_img_aging,#s_lg_img_new{position:absolute;bottom:10px;left:50%;margin-left:-135px}
#form{z-index:1}
#s_lm_wrap{position:absolute;margin-left:-447px;bottom:0;left:50%;z-index:0;height:30px;width:895px;line-height:30px;text-align:center}
.s-skin-hasbg #s_lm_wrap{background:0 0;background-image:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,.3)),to(rgba(0,0,0,.3)));background-image:-moz-linear-gradient(rgba(0,0,0,.3) 0,rgba(0,0,0,.3) 100%);background-image:-ms-linear-gradient(rgba(0,0,0,.3) 0,rgba(0,0,0,.3) 100%);background-image:-o-linear-gradient(rgba(0,0,0,.3) 0,rgba(0,0,0,.3) 100%);background-image:linear-gradient(rgba(0,0,0,.3) 0,rgba(0,0,0,.3) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66000000, endColorstr=#66000000)}
#s_lm_wrap.s-down{display:none}
#lm{color:#666;height:15px;line-height:16px;padding:7px 0}
#lm a{text-decoration:underline;color:#666}
#nv{margin:0 0 5px;_margin-bottom:4px;padding:2px 0 0;text-align:left;text-indent:50px}
#nv a,#nv b{margin-left:19px}
#lk,#nv a,#nv b,.btn{font-size:14px}
.s-down .s_form{padding-left:0;margin-top:0;min-height:0}
.s_form .tools{position:absolute;right:-55px}
.s_form_wrapper{height:100%}
#head_wrapper.s-down #mCon span{color:#000}
#lk{margin:33px 0}
#lk span{font:14px "\5b8b\4f53"}
#lh{margin:16px 0 5px;word-spacing:3px}
#mCon{height:15px;line-height:15px;width:28px;padding:10px 8px 0 0;cursor:pointer;background:url('https://pss.bdstatic.com/static/superman/img/spis7-d578e7ff4b.png') no-repeat -684px -605px}
#mCon span{color:#333;cursor:default;display:block}
#mCon .hw{text-decoration:underline;cursor:pointer}
#mMenu{width:56px;border:1px solid #9b9b9b;list-style:none;position:absolute;right:-9px;top:30px;display:none;background:#fff;box-shadow:1px 1px 2px #ccc;-moz-box-shadow:1px 1px 2px #ccc;-webkit-box-shadow:1px 1px 2px #ccc;filter:progid:DXImageTransform.Microsoft.Shadow(Strength=2, Direction=135, Color="#cccccc")\9}
#mMenu a,#mMenu a:visited{color:#00c;width:100%;height:100%;display:block;line-height:22px;text-indent:6px;text-decoration:none;filter:none\9}
#mMenu a:hover{background:#ebebeb}
#mMenu .ln{height:1px;background:#ebebeb;overflow:hidden;font-size:1px;line-height:1px;margin-top:-1px}
#cp,#cp a{color:#77c}
#tb_mr{color:#00c;cursor:pointer;position:relative;z-index:200}
#tb_mr b{font-weight:400}
#nv a,#tb_mr b{text-decoration:underline}
#nv a{color:#00c}
#hwr_div,#loading{z-index:3000}
.bd_bear_home{display:none}
#mHolder{display:none}
#mHolder .c-icon{right:0;top:0;position:absolute;float:right;width:15px;height:15px}
.main{display:none}
#s_feed{display:none}
.s-ps-sug{border:1px solid #ccc!important;box-shadow:1px 1px 3px #ededed;-webkit-box-shadow:1px 1px 3px #ededed;-moz-box-shadow:1px 1px 3px #ededed;-o-box-shadow:1px 1px 3px #ededed;position:absolute;top:32px;left:0}
.s-ps-sug table{width:100%;background:#fff;cursor:default}
.s-ps-sug td{color:#000;font:14px arial;height:25px;line-height:25px;padding:0 8px}
.s-ps-sug td b{color:#000}
.s-ps-sug .mo{background:#ebebeb;cursor:pointer}
.s-ps-sug .ml{background:#fff}
.s-ps-sug td.sug_storage{color:#7a77c8}
.s-ps-sug td.sug_storage b{color:#7a77c8}
.s-ps-sug .sug_del{font-size:12px;color:#666;text-decoration:underline;float:right;cursor:pointer;display:none}
.s-ps-sug .sug_del{font-size:12px;color:#666;text-decoration:underline;float:right;cursor:pointer;display:none}
.s-ps-sug .mo .sug_del{display:block}
.s-ps-sug .sug_ala{border-bottom:1px solid #e6e6e6}
.s-ps-sug td h3{line-height:14px;margin:6px 0 4px 0;font-size:12px;font-weight:400;color:#7b7b7b;padding-left:20px;background:url(img/sug_bd.png) no-repeat left center}
.s-ps-sug td p{font-size:14px;font-weight:700;padding-left:20px}
.s-ps-sug td p span{font-size:12px;font-weight:400;color:#7b7b7b}
#s_user_center{font-weight:400;background-position:right -223px\9}
#s_user_center_menu{right:131px}
.s-ps-islite #nv{padding-top:22px;line-height:16px;height:16px;margin-bottom:13px}
#form .bdsug .bdsug-direct{width:auto;padding:0;border-bottom:1px solid #f1f1f1}
#head_wrapper .bdsug .bdsug-direct p{color:#00c;font-weight:700;line-height:34px;padding:0 8px;margin-top:0;cursor:pointer;white-space:nowrap;overflow:hidden}
#head_wrapper .bdsug .bdsug-direct p img{width:16px;height:16px;margin:7px 6px 9px 0;vertical-align:middle}
#head_wrapper .bdsug .bdsug-direct p span{margin-left:8px}
#head_wrapper .bdsug .bdsug-direct p i{font-size:12px;line-height:100%;font-style:normal;font-weight:400;color:#fff;background-color:#2b99ff;display:inline;text-align:center;padding:1px 5px;*padding:2px 5px 0 5px;margin-left:8px;overflow:hidden}
#result_logo,#s_tab,#u,#wrapper_wrapper{display:none}
#prefpanel{background:#fafafa;display:none;opacity:0;position:fixed;_position:absolute;top:-359px;z-index:500;width:100%;min-width:960px;border-bottom:1px solid #ebebeb;*left:0!important;text-align:left}
#prefpanel form{_width:850px}
@font-face{font-family:cIconfont;src:url('https://pss.bdstatic.com/static/superman/font/iconfont-cdfecb8456.eot');src:url('https://pss.bdstatic.com/static/superman/font/iconfont-cdfecb8456.eot?#iefix') format('embedded-opentype'),url('https://pss.bdstatic.com/static/superman/font/iconfont-fa013548a9.woff2') format('woff2'),url('https://pss.bdstatic.com/static/superman/font/iconfont-840387fb42.woff') format('woff'),url('https://pss.bdstatic.com/static/superman/font/iconfont-4530e108b6.ttf') format('truetype'),url('https://pss.bdstatic.com/static/superman/font/iconfont-74fcdd51ab.svg#iconfont') format('svg')}
.ai-wrapper{width:560px;margin-bottom:40px}
.header-ai-main{display:block;position:relative;margin:0 auto;border-radius:16px;box-sizing:content-box;background:#fff;padding:14px 32px 40px}
.s-news-no-logged-rank-wrapper{top:40px;margin-top:-4px}
.s-news-logged-rank-wrapper{top:26px;z-index:9;margin-top:-4px}
.s-news-logged-rank-wrapper .hot-news-wrapper .s-news-rank-content .title-content .title-content-mark{top:-2px}
.s-news-rank-wrapper{position:absolute;right:0}
.c-gap-top-small{margin-top:3px}
.c-gap-top{margin-top:7px}
.c-gap-top-large{margin-top:11px}
.c-gap-top-mini{margin-top:2px}
.c-gap-top-xsmall{margin-top:4px}
.c-gap-top-middle{margin-top:10px}
.c-gap-bottom-small{margin-bottom:3px}
.c-gap-bottom{margin-bottom:7px}
.c-gap-bottom-large{margin-bottom:11px}
.c-gap-bottom-mini{margin-bottom:2px}
.c-gap-bottom-xsmall{margin-bottom:4px}
.c-gap-bottom-middle{margin-bottom:10px}
.c-gap-left{margin-left:12px}
.c-gap-left-small{margin-left:8px}
.c-gap-left-xsmall{margin-left:4px}
.c-gap-left-mini{margin-left:2px}
.c-gap-left-large{margin-left:16px}
.c-gap-left-middle{margin-left:10px}
.c-gap-right{margin-right:12px}
.c-gap-right-small{margin-right:8px}
.c-gap-right-xsmall{margin-right:4px}
.c-gap-right-mini{margin-right:2px}
.c-gap-right-large{margin-right:16px}
.c-gap-right-middle{margin-right:10px}
.c-gap-icon-right-small{margin-right:5px}
.c-gap-icon-right{margin-right:10px}
.c-gap-icon-left-small{margin-left:5px}
.c-gap-icon-left{margin-left:10px}
.c-row{*zoom:1}
.c-row:after{display:block;height:0;content:"";clear:both;visibility:hidden}
.c-span1{width:32px}
.c-span2{width:80px}
.c-span3{width:128px}
.c-span4{width:176px}
.c-span5{width:224px}
.c-span6{width:272px}
.c-span7{width:320px}
.c-span8{width:368px}
.c-span9{width:416px}
.c-span10{width:464px}
.c-span11{width:512px}
.c-span12{width:560px}
.c-span10,.c-span11,.c-span12,.c-span2,.c-span3,.c-span4,.c-span5,.c-span6,.c-span7,.c-span8,.c-span9{float:left;_display:inline;margin-right:16px;list-style:none}
.c-span-last{margin-right:0}
.c-span-last-s{margin-right:0}
.c-feed-box .c-span1{width:43px}
.c-feed-box .c-span2{width:90px}
.c-feed-box .c-span3{width:137px}
.c-feed-box .c-span4{width:184px}
.c-feed-box .c-span5{width:231px}
.c-feed-box .c-span6{width:278px}
.c-feed-box .c-span7{width:325px}
.c-feed-box .c-span8{width:372px}
.c-feed-box .c-span9{width:419px}
.c-feed-box .c-span10{width:466px}
.c-feed-box .c-span11{width:513px}
.c-feed-box .c-span12{width:560px}
.c-feed-box .c-span10,.c-feed-box .c-span11,.c-feed-box .c-span12,.c-feed-box .c-span2,.c-feed-box .c-span3,.c-feed-box .c-span4,.c-feed-box .c-span5,.c-feed-box .c-span6,.c-feed-box .c-span7,.c-feed-box .c-span8,.c-feed-box .c-span9{margin-right:4px}
.c-feed-box .c-span-last{margin-right:0}
.c-index{display:inline-block;width:14px;padding:1px 0;line-height:100%;text-align:center;color:#fff;background-color:#8eb9f5;font-size:12px}
.c-index-hot,.c-index-hot1{background-color:#f54545}
.c-index-hot2{background-color:#ff8547}
.c-index-hot3{background-color:#ffac38}
.c-index-single{display:inline-block;background:0 0;color:#9195a3;width:18px;font-size:15px;letter-spacing:-1px}
.c-index-single-hot,.c-index-single-hot1{color:#fe2d46}
.c-index-single-hot2{color:#f60}
.c-index-single-hot3{color:#faa90e}
.c-font-sigma{font:36px/60px Arial,sans-serif}
.c-font-large{font:20px/30px Arial,sans-serif}
.c-font-big{font:20px/30px Arial,sans-serif}
.c-font-special{font:16px/26px Arial,sans-serif}
.c-font-medium{font:14px/24px Arial,sans-serif}
.c-font-middle{font:14px/24px Arial,sans-serif}
.c-font-normal{font:13px/23px Arial,sans-serif}
.c-font-small{font:12px/20px Arial,sans-serif}
.c-font-family{font-family:Arial,sans-serif}
.c-color-t{color:#222}
.c-color-text{color:#333}
.c-color-gray{color:#626675}
.c-color-gray2{color:#9195a3}
.c-color-visited{color:#626675}
.c-color-orange{color:#fa4901}
.c-color-green{color:#0ebe90}
.c-color-ad{color:#77a9f9}
.c-color-red{color:#f63051}
.c-color-red:visited{color:#f63051}
.c-color-warn{color:#ff7900}
.c-color-warn:visited{color:#ff7900}
.c-color-link{color:#3951b3}
.c-btn,.c-btn:visited{color:#333!important}
.c-btn{display:inline-block;overflow:hidden;font-family:inherit;font-weight:400;text-align:center;vertical-align:middle;outline:0;border:0;height:30px;width:80px;line-height:30px;font-size:13px;border-radius:6px;padding:0;background-color:#f5f5f6;*zoom:1;cursor:pointer}
.c-btn:hover{background-color:#315efb;color:#fff!important}
a.c-btn{text-decoration:none}
button.c-btn{*overflow:visible;border:0}
button.c-btn::-moz-focus-inner{padding:0;border:0}
.c-btn-disable{color:#c4c7ce!important}
.c-btn-disable:visited{color:#c4c7ce!important}
.c-btn-disable:hover{cursor:default;color:#c4c7ce!important;background-color:#f5f5f6}
.c-btn-mini{height:24px;width:48px;line-height:24px}
.c-btn-mini .c-icon{margin-top:2px}
.c-btn-large{height:30px;line-height:30px;font-size:14px}
button.c-btn-large{height:30px;_line-height:24px}
.c-btn-large .c-icon{margin-top:7px;_margin-top:6px}
.c-btn-primary,.c-btn-primary:visited{color:#fff!important}
.c-btn-primary{background-color:#4e6ef2}
.c-btn-primary:hover{background-color:#315efb}
.c-btn-weak{height:24px;line-height:24px;border-radius:4px;font-size:12px}
.c-btn-add{width:32px;height:32px;line-height:32px;text-align:center;color:#9195a3!important}
.c-btn-add:hover{background-color:#4e6ef2;color:#fff!important}
.c-btn-add .c-icon{float:none}
.c-btn-add-disable:hover{cursor:default;color:#c4c7ce!important;background-color:#f5f5f6}
.c-select{position:relative;display:inline-block;width:96px;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;vertical-align:middle;color:#222;font:13px/23px Arial,sans-serif}
.c-select-selection{display:block;height:30px;line-height:29px;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;padding:0 26px 0 10px;background-color:#fff;border-radius:6px;border:1px solid #d7d9e0;outline:0;user-select:none;cursor:pointer;position:relative;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.c-select-arrow,.c-select-arrow-up{position:absolute;top:-1px;right:10px;color:#9195a3;font-size:16px}
.c-select-dropdown{display:none;position:absolute;padding-top:4px;top:25px;z-index:999;left:0;width:94px;box-sizing:content-box;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;background:#fff;border-radius:0 0 6px 6px;border:1px solid #d7d9e0;border-top:0;zoom:1}
.c-select-split{border-top:1px solid #f5f5f5;margin:0 5px}
.c-select-dropdown-list{padding:0;margin:5px 0 0;list-style:none}
.c-select-dropdown-list.c-select-scroll{max-height:207px;overflow-y:auto;overflow-x:hidden;margin-right:5px;margin-bottom:9px}
.c-select-dropdown-list.c-select-scroll::-webkit-scrollbar{width:2px}
.c-select-dropdown-list.c-select-scroll::-webkit-scrollbar-track{width:2px;background:#f5f5f6;border-radius:1px}
.c-select-dropdown-list.c-select-scroll::-webkit-scrollbar-thumb{width:2px;height:58px;background-color:#4e71f2;border-radius:1px}
.c-select-dropdown-list.c-select-scroll .c-select-item:last-child{margin:0}
.c-select-item{margin:0 0 4px;padding:0 10px;clear:both;white-space:nowrap;list-style:none;cursor:pointer;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.c-select-item:hover{color:#315efb}
.c-select-item-selected{color:#315efb}
.c-select-arrow-up{display:none}
.c-select-visible .c-select-selection{border-radius:6px 6px 0 0}
.c-select-visible .c-select-dropdown{display:block}
.c-select-visible .c-select-arrow{display:none}
.c-select-visible .c-select-arrow-up{display:inline-block}
.c-img{position:relative;display:block;min-height:1px;border:0;line-height:0;background:#f5f5f6;overflow:hidden}
.c-img img{width:100%}
.c-img1{width:32px}
.c-img2{width:80px}
.c-img3{width:128px}
.c-img4{width:176px}
.c-img6{width:272px}
.c-img12{width:560px}
.c-feed-box .c-img1{width:43px}
.c-feed-box .c-img2{width:90px}
.c-feed-box .c-img3{width:137px}
.c-feed-box .c-img4{width:184px}
.c-feed-box .c-img6{width:278px}
.c-feed-box .c-img12{width:560px}
.c-img-l,.c-img-s,.c-img-v,.c-img-w,.c-img-x,.c-img-y,.c-img-z{height:0;overflow:hidden}
.c-img-s{padding-bottom:100%}
.c-img-l{padding-bottom:133.33333333%}
.c-img-w{padding-bottom:56.25%}
.c-img-x{padding-bottom:75%}
.c-img-y{padding-bottom:66.66666667%}
.c-img-v{padding-bottom:116.66666667%}

百度网页的源代码有大约40万个字符组成,在此之前,有没有人想过看似这么简单的页面源代码这么多,由于字数太多,我们就只展示十分之一

接下来,把这些源代码装到html文件里运行试一下,就能得到一个百度的界面

然后,就可以干一些有趣的事:

  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值