

作者 VictorChan
本文转自知乎,转载需授权
大家好,我是Victor 278,由于本人是做前端的,Python学来作知识扩充的,看到非常多的小伙伴高呼着想从0开始学爬虫,这里开始写定向爬虫从0开始,献给想学爬虫的零基础新人们,欢迎各位大佬们的指点。
1、零基础的新人;
2、Python刚刚懂基础语法的新人;
1、Python语法基础;
2、请阅读或者收藏以下几个网站:
1)Requests库
http://cn.python-requests.org/zh_CN/latest/
2)BeautifulSoup4库
https://www.crummy.com/software/BeautifulSoup/bs4/doc/
没有Python基础的新人,我建议可以学习以下资料:
1、官方最新的英文文档(https://docs.python.org/3/)
2、python 3.60版本中文文档(http://www.pythondoc.com/pythontutorial3/index.html)
3、廖雪峰Python教程(https://www.liaoxuefeng.com/)
备注:书籍也有很多选择,但是其实入门教程讲来讲去都是那些东西,不做细究,你随意挑一本完完整整的学习好比你浪费时间选择教材要强多了。
我假设你已经符合上述的标准,现在我们就来开始第一个爬虫的网站,我们首先挑选一个下手;
附上URL:中国天气网(http://www.weather.com.cn/weather1d/101280101.shtml#dingzhi_first)
第一步:
请确保你已经安装了Requests和Beautifulsoup4的库,否则你可以打开CMD(命令提示符)然后输入
pip3 install requests
pip3 install Beautifulsoup4
pip3 install lxml
安装完毕后接着打开你的编辑器,这里对编辑器不做纠结,用的顺手就好。
首先我们做爬虫,拿到手第一个步骤都是要先获取到网站的当前页的所有内容,即HTML标签。所以我们先要写一个获取到网页HTML标签的方法。
整个爬虫的的代码搭建我都采用的是将不同的功能做成不同的函数,在最后需要调用的时候进行传参调用就好了。
那么问题来了,为什么要这么做呢?
写代码作为萌新要思考几件事:
1、这个代码的复用性;
2、这个代码的语义化以及功能解耦;
3、是否美观简洁,让别人看你的代码能很清楚的理解你的逻辑;
代码展示:
'''
抓取每天的天气数据
python 3.6.2
url:http://www.weather.com.cn/weather1d/101280101.shtml#dingzhi_first
'''
import requests
import bs4
def get_html(url):
'''
封装请求
'''
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'ContentType':
'text/html; charset=utf-8',
'Accept-Encoding':
'gzip, deflate, sdch',
'Accept-Language':
'zh-CN,zh;q=0.8',
'Connection':
'keep-alive',
}
try:
htmlcontet = requests.get(url, headers=headers, timeout=30)
htmlcontet.raise_for_status()
htmlcontet.encoding = 'utf-8'
return htmlcontet.text
except:
return " 请求失败 "上述代码几个地方我特别说明一下:
'''
抓取每天的天气数据
python 3.6.2
url:http://www.weather.com.cn/weather1d/101280101.shtml#dingzhi_first
'''
import requests
import bs4
养成好习惯代码一开始的注释表明这是一个什么功能的Python文件,使用的版本是什么,URL地址是什么,帮助你下次打开的时候能快速理解这个文件的用途。
由于Requests和Beautifulsoup4是第三方的库,所以在下面要用import来进行引入
然后是
def get_html(url):
'''
封装请求
'''
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'ContentType':
'text/html; charset=utf-8',
'Accept-Encoding':
'gzip, deflate, sdch',
'Accept-Language':
'zh-CN,zh;q=0.8',
'Connection':
'keep-alive',
}
try:
htmlcontet = requests.get(url, headers=headers, timeout=30)
htmlcontet.raise_for_status()
htmlcontet.encoding = 'utf-8'
return htmlcontet.text
except:
return " 请求失败 "
其中
def get_html(url):
构造一个名为get_html的函数,并传入你要请求的URL地址进去,会返回一个请求后的结果,
构造好后,调用的时候直接
url = '包裹你的url'
get_html(url)
然后同样备注好你的这个函数的功能是做什么的,headers里面包裹了一些伪装成浏览器访问的一些头部文件可以直接你复制过去使用。
这里要说一下为什么要做基础的伪装成浏览器,由于有了爬虫,自然就有反爬虫。有些网站为了恶意避免爬虫肆意爬取或者进行攻击等等情况,会做大量的反爬虫。伪装浏览器访问是反爬虫的一小步。
好了我们继续,
htmlcontet = requests.get(url, headers=headers, timeout=30)
htmlcontet.raise_for_status()
htmlcontet.encoding = 'utf-8'
return htmlcontet.text
第一条如果我们看了Requests之后就知道这是一个解析你传入的url,并包含了请求头,响应延时
第二条,如果当前页面响应的情况会返回一个json数据包,我们通过这个语法来确认是否为我们要的成功响应的结果
第三条,解析格式,由于该网站我们可以看到已知字符编码格式为utf-8所以在这里我就写死了是utf-8
最后都没问题后,返回一个页面文件出来
第二步:
拿到一个页面文件后,我们就需要观察一下该网页的HTML结构
这里介绍一下如何观察一个网页的结构,打开F12或者,找个空白的位置右键——>检查
我们大概会看到这样的一个情况:

没错你看到那些这些就是HTML语言,我们爬虫就是要从这些标记里面抓取出我们所需要的内容。
我们现在要抓取这个1日夜间和2日白天的天气数据出来:
我们首先先从网页结构中找出他们的被包裹的逻辑

很清楚的能看到他们的HTML嵌套的逻辑是这样的:
|
|_____
|
|_____
|
|______
|
|_____
|
|_____
|
|_____我们要的内容都包裹在li里面,然后这里我们就要用BeautifulSoup里面的find方法来进行提取查询
我们继续构建一个抓取网页内容的函数,由于我们最终要的数据有两条,所有我先声明一个weather_list的数组来等会保存我要的结果。
代码如下:
def get_content(url):
'''
抓取页面天气数据
'''
weather_list = []
html = get_html(url)
soup = bs4.BeautifulSoup(html, 'lxml')
content_ul = soup.find('div', class_='t').find_all('li')
for content in content_ul:
try:
weather = {}
weather['day'] = content.find('h1').text
weather['temperature'] = content.find(
'p', class_='tem').span.text + content.find(
'p', class_='tem').em.text
weather_list.append(weather)
except:
print('查询不到')
print (weather_list)
同样的话不说第二遍,我们要写好注释。在声明完数组后,我们就可调用刚才封装好的请求函数来请求我们要的URL并返回一个页面文件,接下来就是用Beautifulsoup4里面的语法,用lxml来解析我们的网页文件。
你们可以用
soup = bs4.BeautifulSoup(html, 'lxml')
print (soup)
就可以看到整个HTML结构出现在你眼前,接下来我就们就根据上面整理出来的标签结构来找到我们要的信息
content_ul = soup.find('div', class_='t').find_all('li')
具体方法,要熟读文档,我们找到所有的li后会返回一个这样的结构

这是一个数组的格式,然后我们遍历它,构造一个字典,我们对于的操作字典建立'day','temperature'键值对
for content in content_ul:
try:
weather = {}
weather['day'
] = content.find('h1').text
weather['temperature'] = content.find(
'p', class_='tem').span.text + content.find(
'p', class_='tem').em.text
weather_list.append(weather)
except:
print('查询不到')
print(weather_list)
最后输出

附上完整代码:
'''
抓取每天的天气数据
python 3.6.2
url:http://www.weather.com.cn/weather1d/101190401.shtml
'''
import json
import requests
import bs4
def get_html(url):
'''
封装请求
'''
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'ContentType':
'text/html; charset=utf-8',
'Accept-Encoding':
'gzip, deflate, sdch',
'Accept-Language':
'zh-CN,zh;q=0.8',
'Connection':
'keep-alive',
}
try:
htmlcontet = requests.get(url, headers=headers, timeout=30)
htmlcontet.raise_for_status()
htmlcontet.encoding = 'utf-8'
return htmlcontet.text
except:
return " 请求失败 "
def get_content(url):
'''
抓取页面天气数据
'''
weather_list = []
html = get_html(url)
soup = bs4.BeautifulSoup(html, 'lxml')
content_ul = soup.find('div', class_='t').find('ul', class_='clearfix').find_all('li')
for content in content_ul:
try:
weather = {}
weather['day'] = content.find('h1').text
weather['temperature'] = content.find(
'p', class_='tem').span.text + content.find(
'p', class_='tem').em.text
weather_list.append(weather)
except:
print('查询不到')
print(weather_list)
if __name__ == '__main__':
url = 'http://www.weather.com.cn/weather1d/101190401.shtml'
get_content(url)

长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
微信扫一扫
关注该公众号
parent_width ? parent_width : width,
outerW = getOuterW(dom)||0,
outerH = getOuterH(dom)||0,
videoW = width - outerW,
videoH = videoW/ratio_,
height = videoH + outerH;
return {w:width,h:height,vh:videoH,vw:videoW,ratio:ratio_};
};
(function(){
var iframe = document.getElementsByTagName('iframe');
for (var i=0,il=iframe.length;i=0 && child.getAttribute("data-vid")==vid){
child.style.cssText += "height: " + h + "px !important;";
child.style.display = "";
}
}
}
}
})();
})();
var not_in_mm_css = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg/not_in_mm36906d.css";
var windowwx_css = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg/page_mp_article_improve_winwx31619e.css";
var article_improve_combo_css = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg/page_mp_article_improve_combo3b540a.css";
var tid = "";
var aid = "";
var clientversion = "";
var appuin = "MzA3OTAxMDQzNQ=="||"";
var source = "0";
var ascene = "";
var subscene = "";
var abtest_cookie = "";
var scene = 75;
var itemidx = "";
var appmsg_token = "";
var _copyright_stat = "0";
var _ori_article_type = "";
var nickname = "CDA数据分析师";
var appmsg_type = "9";
var ct = "1516701504";
var publish_time = "2018-01-23" || "";
var user_name = "gh_19b070397d24";
var user_name_new = "";
var fakeid = "";
var version = "";
var is_limit_user = "0";
var round_head_img = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz/pxMrQvgWLUJquyWK0DAIhguiaxsfrjdpXYBfB7fSyLzHjdiaVduedFOx03t5PntYNyAIa8PLNLjmfPdWcRadUJoA/0";
var ori_head_img_url = "http://wx.qlogo.cn/mmhead/Q3auHgzwzM7Dbfiado7omniaUnhKRUudsuJNvDqTBgwPzqH1Ficp7Th7g/132";
var msg_title = "如何用 Python 爬取天气预报";
var msg_desc = "如何用 Python 爬取天气预报";
var msg_cdn_url = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz_jpg/pxMrQvgWLUKLwWB0bIsHjKmOTb8uc01OrF3nY5ric2cdUT4f7uwxibBCff3o5biaicH9HU53I6c6fusEfpWw9P4IzQ/0?wx_fmt=jpeg";
var msg_link = "http://mp.weixin.qq.com/s?__biz=MzA3OTAxMDQzNQ==\x26amp;mid=2650613815\x26amp;idx=2\x26amp;sn=9747fe2807640a3c85cd32dafa2da8e7\x26amp;chksm=87b387dbb0c40ecdef60d778fec0ffae36c2f9bd7ffb2527569094c4d5027b871b665669adda#rd";
var user_uin = "0"*1;
var msg_source_url = 'https://jinshuju.net/f/lwxYBl';
var img_format = 'jpeg';
var srcid = '';
var req_id = '2411vptVou7vKQeh73V995uZ';
var networkType;
var appmsgid = '' || '2650613815'|| "";
var comment_id = "1864690079" || "1864690079" * 1;
var comment_enabled = "" * 1;
var is_need_reward = "0" * 1;
var is_https_res = ("" * 1) && (location.protocol == "https:");
var msg_daily_idx = "1" || "";
var profileReportInfo = "" || "";
var devicetype = "";
var source_encode_biz = "";
var source_username = "";
var reprint_ticket = "";
var source_mid = "";
var source_idx = "";
var source_biz = "";
var show_comment = "";
var __appmsgCgiData = {
wxa_product : ""*1,
show_msg_voice: "0"*1,
can_use_page : "0"*1,
is_wxg_stuff_uin : "0"*1,
card_pos : "",
copyright_stat : "0",
source_biz : "",
hd_head_img : "http://wx.qlogo.cn/mmhead/Q3auHgzwzM7Dbfiado7omniaUnhKRUudsuJNvDqTBgwPzqH1Ficp7Th7g/0"||(window.location.protocol+"//"+window.location.host + "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/pic/appmsg/pic_rumor_link.2x264e76.jpg")
};
var _empty_v = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/pic/pages/voice/empty26f1f1.mp3";
var copyright_stat = "0" * 1;
var pay_fee = "" * 1;
var pay_timestamp = "";
var need_pay = "" * 1;
var need_report_cost = "0" * 1;
var use_tx_video_player = "0" * 1;
var appmsg_fe_filter = "contenteditable";
var friend_read_source = "" || "";
var friend_read_version = "" || "";
var friend_read_class_id = "" || "";
var is_only_read = "1" * 1;
var read_num = "" * 1;
var like_num = "" * 1;
var liked = "" == 'true' ? true : false;
var is_temp_url = "" ? 1 : 0;
var send_time = "";
var icon_emotion_switch = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/emotion/icon_emotion_switch.2x2f1273.png";
var icon_emotion_switch_active = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/emotion/icon_emotion_switch_active.2x2f1273.png";
var icon_loading_white = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/common/icon_loading_white2805ea.gif";
var icon_audio_unread = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/audio/icon_audio_unread26f1f1.png";
var icon_qqmusic_default = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/qqmusic/icon_qqmusic_default.2x26f1f1.png";
var icon_qqmusic_source = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/qqmusic/icon_qqmusic_source393e3a.png";
var icon_kugou_source = "//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/kugou/icon_kugou_source393e3a.png";
var topic_default_img = '//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/topic/pic_book_thumb.2x2e4987.png';
var comment_edit_icon = '//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/appmsg/icon_edit25ded2.png';
var comment_loading_img = '//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/icon/common/icon_loading_white2805ea.gif';
var voice_in_appmsg = {
"1":"1"
};
var wxa_img_alert = "" != 'false';
var weapp_sn_arr_json = "" || "";
var ban_scene = "0" * 1;
var svr_time = "1516765622" * 1;
var is_transfer_msg = ""*1||0;
var malicious_title_reason_id = "0" * 1;
window.wxtoken = "";
window.is_login = '0' * 1;
window.__moon_initcallback = function(){
if(!!window.__initCatch){
window.__initCatch({
idkey : 27611+2,
startKey : 0,
limit : 128,
badjsId: 43,
reportOpt : {
uin : uin,
biz : biz,
mid : mid,
idx : idx,
sn : sn
},
extInfo : {
network_rate : 0.01,
badjs_rate: 0.1
}
});
}
}
window.__moon_host = 'res.wx.qq.com';window.__moon_mainjs = 'appmsg/index.js';window.moon_map = {"new_video/player.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/new_video/player.html39e24c.js","biz_wap/zepto/touch.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/zepto/touch34c264.js","biz_wap/zepto/event.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/zepto/event34c264.js","biz_wap/zepto/zepto.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/zepto/zepto34c264.js","page/pages/video.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/pages/video.css3767b8.js","a/appdialog_confirm.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/appdialog_confirm.html34f0d8.js","widget/wx_profile_dialog_primary.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/widget/wx_profile_dialog_primary.css34f0d8.js","appmsg/emotion/caret.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/caret278965.js","new_video/player.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/new_video/player39e24c.js","a/appdialog_confirm.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/appdialog_confirm34c32a.js","biz_wap/jsapi/cardticket.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/jsapi/cardticket34c264.js","biz_common/utils/emoji_panel_data.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/emoji_panel_data3518c6.js","biz_common/utils/emoji_data.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/emoji_data3518c6.js","appmsg/emotion/textarea.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/textarea353f34.js","appmsg/emotion/nav.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/nav278965.js","appmsg/emotion/common.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/common3518c6.js","appmsg/emotion/slide.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/slide2a9cd9.js","pages/loadscript.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/loadscript39aac6.js","pages/music_report_conf.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/music_report_conf39aac6.js","pages/report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/report3b5aa4.js","pages/player_adaptor.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/player_adaptor39d6ee.js","pages/music_player.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/music_player3af14e.js","appmsg/emotion/dom.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/dom31ff31.js","appmsg/comment_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/comment_tpl.html36c376.js","biz_wap/utils/fakehash.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/fakehash38c7af.js","biz_common/utils/wxgspeedsdk.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/wxgspeedsdk3518c6.js","a/sponsor.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/sponsor39e101.js","a/app_card.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/app_card393ef4.js","a/ios.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/ios393966.js","a/android.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/android393966.js","a/profile.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/profile31ff31.js","a/cpc_a_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/cpc_a_tpl.html3b540a.js","a/sponsor_a_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/sponsor_a_tpl.html36c7cf.js","a/a_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/a_tpl.html393ef4.js","a/mpshop.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/mpshop311179.js","a/wxopen_card.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/wxopen_card3a95b8.js","a/card.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/card311179.js","biz_wap/utils/position.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/position34c264.js","a/a_report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/a_report393966.js","appmsg/my_comment_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/my_comment_tpl.html36906d.js","appmsg/cmt_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/cmt_tpl.html369d00.js","sougou/a_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/sougou/a_tpl.html2c6e7c.js","appmsg/emotion/emotion.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/emotion/emotion353f34.js","biz_wap/utils/wapsdk.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/wapsdk34c264.js","biz_common/utils/report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/report3518c6.js","appmsg/open_url_with_webview.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/open_url_with_webview3145f0.js","biz_common/utils/http.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/http3518c6.js","biz_common/utils/cookie.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/cookie3518c6.js","appmsg/topic_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/topic_tpl.html31ff31.js","pages/weapp_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/weapp_tpl.html36906d.js","biz_common/utils/monitor.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/monitor3518c6.js","appmsg/weapp_common.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/weapp_common3af55a.js","pages/voice_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/voice_tpl.html38518d.js","pages/kugoumusic_ctrl.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/kugoumusic_ctrl393e3a.js","pages/qqmusic_ctrl.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/qqmusic_ctrl39b68c.js","pages/voice_component.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/voice_component3af14e.js","pages/qqmusic_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/qqmusic_tpl.html393e3a.js","new_video/ctl.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/new_video/ctl2d441f.js","a/testdata.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/testdata3a6969.js","appmsg/reward_entry.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/reward_entry3b1cff.js","appmsg/comment.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/comment3944ad.js","appmsg/like.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/like375fea.js","pages/version4video.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/version4video3a9bef.js","a/a.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/a/a3b540a.js","rt/appmsg/getappmsgext.rt.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/rt/appmsg/getappmsgext.rt2c21f6.js","biz_wap/utils/storage.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/storage34c264.js","biz_common/tmpl.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/tmpl3518c6.js","appmsg/share_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/share_tpl.html36906d.js","appmsg/img_copyright_tpl.html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/img_copyright_tpl.html2a2c13.js","pages/video_ctrl.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/pages/video_ctrl36ebcf.js","biz_common/ui/imgonepx.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/ui/imgonepx3518c6.js","biz_common/utils/respTypes.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/respTypes3518c6.js","biz_wap/utils/log.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/log34c264.js","sougou/index.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/sougou/index36913b.js","biz_wap/safe/mutation_observer_report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/safe/mutation_observer_report34c264.js","appmsg/fereport.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/fereport3b1088.js","appmsg/report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/report3404b3.js","appmsg/report_and_source.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/report_and_source3a7477.js","appmsg/page_pos.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/page_pos3a95b8.js","appmsg/cdn_speed_report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/cdn_speed_report3097b2.js","appmsg/wxtopic.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/wxtopic31a3be.js","appmsg/new_index.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/new_index36906d.js","appmsg/weapp.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/weapp3af55a.js","appmsg/weproduct.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/weproduct3af55a.js","appmsg/voicemsg.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/voicemsg3b1748.js","appmsg/autoread.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/autoread3af14e.js","appmsg/voice.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/voice38518d.js","appmsg/qqmusic.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/qqmusic39dc43.js","appmsg/iframe.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/iframe39ab71.js","appmsg/product.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/product393966.js","appmsg/review_image.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/review_image3af55a.js","appmsg/outer_link.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/outer_link275627.js","appmsg/copyright_report.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/copyright_report2ec4b2.js","appmsg/async.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/async3b27d5.js","biz_wap/ui/lazyload_img.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/ui/lazyload_img3af55a.js","biz_common/log/jserr.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/log/jserr3518c6.js","appmsg/share.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/share3b4418.js","appmsg/cdn_img_lib.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/cdn_img_lib38b7bb.js","biz_common/utils/url/parse.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/url/parse36ebcf.js","page/appmsg/not_in_mm.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg/not_in_mm.css36906d.js","page/appmsg/page_mp_article_improve_combo.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg/page_mp_article_improve_combo.css3b540a.js","page/appmsg_new/not_in_mm.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg_new/not_in_mm.css36f05c.js","page/appmsg_new/combo.css":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg_new/combo.css3b540a.js","biz_wap/jsapi/core.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/jsapi/core3b0568.js","biz_common/dom/event.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/dom/event3a25e9.js","appmsg/test.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/test354009.js","biz_wap/utils/mmversion.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/mmversion34c264.js","appmsg/max_age.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/max_age2fdd28.js","biz_common/dom/attr.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/dom/attr3518c6.js","biz_wap/utils/ajax.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/ajax38c31a.js","appmsg/log.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/log300330.js","biz_common/dom/class.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/dom/class3518c6.js","biz_wap/utils/device.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_wap/utils/device34c264.js","biz_common/utils/string/html.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/biz_common/utils/string/html3518c6.js","appmsg/index.js":"//res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/appmsg/index3b1748.js"};
r;r++){
var a=t[r].split("=");
a[0]&&a[1]&&n.push(a[0]+"="+encodeURIComponent(a[1]));
}
var s=new window.Image;
return void(s.src=(o+n.join("&")).substr(0,1024));
}
var c;
if(window.ActiveXObject)try{
c=new ActiveXObject("Msxml2.XMLHTTP");
}catch(d){
try{
c=new ActiveXObject("Microsoft.XMLHTTP");
}catch(_){
c=!1;
}
}else window.XMLHttpRequest&&(c=new XMLHttpRequest);
c&&(c.open(e,o,!0),c.setRequestHeader("cache-control","no-cache"),c.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"),
c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.send(t));
}
function s(e){
return function(o,t){
if("string"==typeof o)try{
o=new Function(o);
}catch(n){
throw n;
}
var r=[].slice.call(arguments,2),a=o;
return o=function(){
try{
return a.apply(this,r.length&&r||arguments);
}catch(e){
throw e.stack&&console&&console.error&&console.error("[TryCatch]"+e.stack),_&&window.__moon_report&&(window.__moon_report([{
offset:O,
log:"timeout_error;host:"+top.location.host,
e:e
}]),i(f)),e;
}
},e(o,t);
};
}
function c(e){
return function(o,t,n){
if("undefined"==typeof n)var n=!1;
var r=this,a=t||function(){};
return t=function(){
try{
return a.apply(r,arguments);
}catch(e){
throw e.stack&&console&&console.error&&console.error("[TryCatch]"+e.stack),_&&window.__moon_report&&(window.__moon_report([{
offset:y,
log:"listener_error;type:"+o+";host:"+top.location.host,
e:e
}]),i(f)),e;
}
},a.moon_lid=b,D[b]=t,b++,e.call(r,o,t,n);
};
}
function d(e){
return function(o,t,n){
if("undefined"==typeof n)var n=!1;
var r=this;
return t=D[t.moon_lid],e.call(r,o,t,n);
};
}
var _,m,w,l,u,p,f,h=/MicroMessenger/i.test(navigator.userAgent),g=window.define,v=0,y=2,x=4,O=9,j=10;
if(window.__initCatch=function(e){
_=e.idkey,m=e.startKey||0,w=e.limit,l=e.badjsId,u=e.reportOpt||"",p=e.extInfo||{},
p.rate=p.rate||.5;
},window.__moon_report=function(e,o){
var i=.5;
if(p&&p.rate&&(i=p.rate),o&&"number"==typeof o&&(i=o),!(!/mp\.weixin\.qq\.com/.test(location.href)&&!/payapp\.weixin\.qq\.com/.test(location.href)||Math.random()>i||!h||top!=window&&!/mp\.weixin\.qq\.com/.test(top.location.href))&&(n(e)&&(e=[e]),
t(e)&&""!=_)){
var s="",c=[],d=[],u=[],f=[];
"number"!=typeof w&&(w=1/0);
for(var g=0;gw||"number"!=typeof v.offset||v.offset==x&&p&&p.network_rate&&Math.random()>=p.network_rate)){
var y=1/0==w?m:m+v.offset;
c[g]="[moon]"+_+"_"+y+";"+v.log+";"+r(v.e||{})||"",d[g]=y,u[g]=1;
}
}
for(var O=0;O0){
a("POST",location.protocol+"//mp.weixin.qq.com/mp/jsmonitor?","idkey="+f.join(";")+"&r="+Math.random()+"&lc="+c.length+s);
var i=1;
if(p&&p.badjs_rate&&(i=p.badjs_rate),l&&Math.random()=10))try{
S.call(window.localStorage,e,o);
}catch(t){
t.stack&&console&&console.error&&console.error("[TryCatch]"+t.stack),window.__moon_report([{
offset:j,
log:"localstorage_error;"+t.toString(),
e:t
}]),I++,I>=3&&window.moon&&window.moon.clear&&moon.clear();
}
};
}
window.seajs&&g&&(window.define=function(){
for(var o,t=[],n=arguments&&arguments[0],a=0,s=arguments.length;s>a;a++){
var c=o=arguments[a];
"function"==typeof o&&(o=function(){
try{
return c.apply(this,arguments);
}catch(o){
throw"string"==typeof n&&console.error("[TryCatch][DefineeErr]id:"+n),o.stack&&console&&console.error&&console.error("[TryCatch]"+o.stack),
_&&window.__moon_report&&(window.__moon_report([{
offset:v,
log:"define_error;id:"+n+";",
e:o
}]),i(f)),e(" [define_error]"+JSON.stringify(r(o))),o;
}
},o.toString=function(e){
return function(){
return e.toString();
};
}(arguments[a])),t.push(o);
}
return g.apply(this,t);
});
}(),function(o){
function t(e,o,t){
return window.__DEBUGINFO?(window.__DEBUGINFO.res_list||(window.__DEBUGINFO.res_list=[]),
window.__DEBUGINFO.res_list[e]?(window.__DEBUGINFO.res_list[e][o]=t,!0):!1):!1;
}
function n(e){
var o=new TextEncoder("utf-8").encode(e),t=crypto.subtle||crypto.webkitSubtle;
return t.digest("SHA-256",o).then(function(e){
return r(e);
});
}
function r(e){
for(var o=[],t=new DataView(e),n=0;nr;++r)if(o.call(t,e[r],r,e)===!1)return;
}else{
if("Object"!==n&&a!=e)throw"unsupport type";
if(a==e){
for(var r=e.length-1;r>=0;r--){
var s=a.key(r),c=a.getItem(s);
if(o.call(t,c,s,e)===!1)return;
}
return;
}
for(var r in e)if(e.hasOwnProperty(r)&&o.call(t,e[r],r,e)===!1)return;
}
}
}
var a=o.localStorage,s=document.head||document.getElementsByTagName("head")[0],c=1,d=11,_=12,m=13,w=window.__allowLoadResFromMp?1:2,l=window.__allowLoadResFromMp?1:0,u=w+l,p=window.testenv_reshost||window.__moon_host||"res.wx.qq.com",f=new RegExp("^(http(s)?:)?//"+p);
window.__loadAllResFromMp&&(p="mp.weixin.qq.com",w=0,u=w+l);
var h=0,g={
prefix:"__MOON__",
loaded:[],
unload:[],
clearSample:Math.random()=1296e6){
g.clear();
try{
!!a&&a.setItem(g.prefix+"clean_time",+new Date);
}catch(m){}
}
}
i(moon_map,function(i,s){
if(t=g.prefix+s,r=!!i&&i.replace(f,""),e=!!a&&a.getItem(t),version=!!a&&(a.getItem(t+"_ver")||"").replace(f,""),
g.mod_num++,r&&-1!=r.indexOf(".css")?g.cacheData.css_mod_num++:r&&-1!=r.indexOf(".js")&&g.cacheData.js_mod_num++,
g.clearSample||!e||r!=version)g.unload.push(r.replace(f,"")),r&&-1!=r.indexOf(".css")?e?r!=version&&g.cacheData.css_expired_num++:g.cacheData.css_not_hit_num++:r&&-1!=r.indexOf(".js")&&(e?r!=version&&g.cacheData.js_expired_num++:g.cacheData.js_not_hit_num++);else{
if("https:"==location.protocol&&window.moon_hash_map&&window.moon_hash_map[s]&&window.crypto)try{
n(e).then(function(e){
window.moon_hash_map[s]!=e&&console.log(s);
});
}catch(c){}
try{
var d="//# sourceURL="+s+"\n//@ sourceURL="+s;
o.eval.call(o,'define("'+s+'",[],'+e+")"+d),g.hit_num++,r&&-1!=r.indexOf(".css")?g.cacheData.css_hit_num++:r&&-1!=r.indexOf(".js")&&g.cacheData.js_hit_num++;
}catch(c){
g.unload.push(r.replace(f,""));
}
}
}),g.load(g.genUrl());
},
genUrl:function(){
var e=g.unload;
if(!e||e.length<=0)return[];
var o,t,n="",r=[],i={},a=-1!=location.search.indexOf("no_moon2=1"),s="//"+p;
-1!=location.href.indexOf("moon_debug2=1")&&(s="//mp.weixin.qq.com");
for(var c=0,d=e.length;d>c;++c){
/^\/(.*?)\//.test(e[c]);
var _=/^\/(.*?)\//.exec(e[c]);
_.length<2||!_[1]||(t=_[1],n=i[t],n?(o=n+","+e[c],o.length>1e3||a?(r.push(n+"?v="+g.version),
n=location.protocol+s+e[c],i[t]=n):(n=o,i[t]=n)):(n=location.protocol+s+e[c],i[t]=n));
}
for(var m in i)i.hasOwnProperty(m)&&r.push(i[m]);
return r;
},
load:function(e){
if(window.__wxgspeeds&&(window.__wxgspeeds.mod_num=g.mod_num,window.__wxgspeeds.hit_num=g.hit_num),
!e||e.length<=0)return seajs.combo_status=seajs.COMBO_LOADED,seajs.run(),console.debug&&console.debug("[moon] load js complete, all in cache, cost time : 0ms, total count : "+g.mod_num+", hit num: "+g.hit_num),
void window.__moonclientlog.push("[moon] load js complete, all in cache, cost time : 0ms, total count : "+g.mod_num+", hit num: "+g.hit_num);
seajs.combo_status=seajs.COMBO_LOADING;
var o=0,t=+new Date;
window.__wxgspeeds&&(window.__wxgspeeds.combo_times=[],window.__wxgspeeds.combo_times.push(t)),
i(e,function(n){
g.request(n,u,function(){
if(window.__wxgspeeds&&window.__wxgspeeds.combo_times.push(+new Date),o++,o==e.length){
var n=+new Date-t;
window.__wxgspeeds&&(window.__wxgspeeds.mod_downloadtime=n),seajs.combo_status=seajs.COMBO_LOADED,
seajs.run(),console.debug&&console.debug("[moon] load js complete, url num : "+e.length+", total mod count : "+g.mod_num+", hit num: "+g.hit_num+", use time : "+n+"ms"),
window.__moonclientlog.push("[moon] load js complete, url num : "+e.length+", total mod count : "+g.mod_num+", hit num: "+g.hit_num+", use time : "+n+"ms");
}
});
});
},
request:function(o,n,r){
if(o){
n=n||0,o.indexOf("mp.weixin.qq.com")>-1&&((new Image).src=location.protocol+"//mp.weixin.qq.com/mp/jsmonitor?idkey=27613_32_1&r="+Math.random(),
window.__moon_report([{
offset:_,
log:"load_script_from_mp: "+o
}],1));
var i=-1;
window.__DEBUGINFO&&(__DEBUGINFO.res_list||(__DEBUGINFO.res_list=[]),__DEBUGINFO.res_list.push({
type:"js",
status:"pendding",
start:+new Date,
end:0,
url:o
}),i=__DEBUGINFO.res_list.length-1),-1!=location.search.indexOf("no_lshttps=1")&&(o=o.replace("http://","https://"));
var a=document.createElement("script");
a.src=o,a.type="text/javascript",a.async=!0,a.down_time=+new Date,a.onerror=function(s){
t(i,"status","error"),t(i,"end",+new Date);
var _=new Error(s);
if(n>=0)if(l>n){
var w=o.replace("res.wx.qq.com","mp.weixin.qq.com");
g.request(w,n,r);
}else g.request(o,n,r);else window.__moon_report&&window.__moon_report([{
offset:c,
log:"load_script_error: "+o,
e:_
}],1);
if(n==l-1&&window.__moon_report([{
offset:d,
log:"load_script_error: "+o,
e:_
}],1),-1==n){
var u="ua: "+window.navigator.userAgent+", time="+(+new Date-a.down_time)+", load_script_error -1 : "+o;
window.__moon_report([{
offset:m,
log:u
}],1);
}
window.__moonclientlog.push("moon load js error : "+o+", error -
"+_.toString()),
e("moon_request_error url:"+o);
},"undefined"!=typeof moon_crossorigin&&moon_crossorigin&&a.setAttribute("crossorigin",!0),
a.onload=a.onreadystatechange=function(){
t(i,"status","loaded"),t(i,"end",+new Date),!a||a.readyState&&!/loaded|complete/.test(a.readyState)||(t(i,"status","200"),
a.onload=a.onreadystatechange=null,"function"==typeof r&&r());
},n--,s.appendChild(a),e("moon_request url:"+o+" retry:"+n);
}
},
setItem:function(e,o){
!!a&&a.setItem(e,o);
},
clear:function(){
a&&(i(a,function(e,o){
~o.indexOf(g.prefix)&&a.removeItem(o);
}),console.debug&&console.debug("[moon] clear"));
},
idkeyReport:function(e,o,t){
t=t||1;
var n=e+"_"+o+"_"+t;
(new Image).src="/mp/jsmonitor?idkey="+n+"&r="+Math.random();
}
};
seajs&&seajs.use&&"string"==typeof window.__moon_mainjs&&seajs.use(window.__moon_mainjs),
window.moon=g;
}(window),window.moon.init();
};
e(),!!window.__moon_initcallback&&window.__moon_initcallback(),window.__wxgspeeds&&(window.__wxgspeeds.moonendtime=+new Date);
}
}
__moonf__(); }, 25);