获取动态加载ajax的数据
2017-10-08 14:58
393 查看
get_info
import re import urllib2 import json import pandas as pd class Qyinyue(object): def __init__(self, url): self.url = url global datas datas = [] self.start() def start(self): my_page = self.get_page() self.get_info(my_page) def get_page(self): url = self.url try: req = urllib2.Request(url, headers={'User-agent': 'Magic Browser'}) my_page = urllib2.urlopen(req).read().decode('utf-8') except urllib2.HTTPError as e: if hasattr(e, 'code'): print "e.code:%s" % e.code elif hasattr(e, 'reason'): print "e.reason:%s" % e.reason return my_page def get_info(self, my_page): find_start = my_page.find('[') end_find = my_page.find(']') my_page = my_page[find_start: end_find + 1] pd_json = json.loads(my_page) datas.extend(pd_json)
mythread
import time import pandas as pd import mythread as mt import get_info as gi if __name__ == '__main__': urlList = [] for i in range(1, 100): urlList.append( 'https://c.y.qq.com/v8/fcg-bin/v8.fcg?channel=singer&page=list&key=all_all_all&pagesize=100&g_tk=5381&jsonpCallback=GetSingerListCallback&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&pagenum=' + str( i)) threadList = [mt.Mythread(gi.Qyinyue, (url,)) for url in urlList] start_time = time.time() for t in threadList: t.setDaemon(True) t.start() for t in threadList: t.join() end_time = time.time() df = pd.DataFrame(gi.datas, columns=['Fother_name', 'Fsinger_id', 'Fsinger_name']) print df print "use the time is %s s" % (end_time - start_time) ''
testmain
import time import pandas as pd import mythread as mt import get_info as gi if __name__ == '__main__': urlList = [] for i in range(1, 100): urlList.append( 'https://c.y.qq.com/v8/fcg-bin/v8.fcg?channel=singer&page=list&key=all_all_all&pagesize=100&g_tk=5381&jsonpCallback=GetSingerListCallback&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&pagenum=' + str( i)) threadList = [mt.Mythread(gi.Qyinyue, (url,)) for url in urlList] start_time = time.time() for t baee in threadList: t.setDaemon(True) t.start() for t in threadList: t.join() end_time = time.time() df = pd.DataFrame(gi.datas, columns=['Fother_name', 'Fsinger_id', 'Fsinger_name']) print df print "use the time is %s s" % (end_time - start_time)
相关文章推荐
- 利用js将ajax获取到的后台数据动态加载至网页中的方法
- 利用js将ajax获取到的后台数据动态加载至网页中
- DataTables+BootStrap组合使用Ajax来获取数据并且动态加载dom的方法(排序,过滤,分页等)
- echarts画圆环统计图并加载动态数据 (ajax获取数据)
- 利用js将ajax获取到的后台数据动态加载至网页中
- 静态页面 写ajax获取接口 加载数据案例
- 获取ajax数据动态添加html内容
- Ajax动态滚动加载数据
- jsTree ajax 获取json数据加载树
- echarts在.Net中使用实例(二) 使用ajax动态加载数据
- 总结Asp.net中Page加载PostData的具体过程 进而解决"获取动态创建的控件的PostData数据"问题
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- Ajax实现动态加载数据
- python3 网络爬虫(二)利用get请求获取网页的动态加载数据
- Echarts -- 条件查询ajax动态获取数据
- 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)
- AJAX 动态加载后台数据 绑定select
- JS使用ajax从xml文件动态获取数据显示的方法
- JS-利用ajax获取json数据,并传入页面生成动态tab
- 关于selectize,ajax动态获取数据,数据类型转换