首页 文章 精选 留言 我的

精选列表

搜索[自适应爬虫],共4674篇文章
优秀的个人博客,低调大师

Python爬虫(三)——开封市58同城出租房决策树构建

决策树框架: 1 # coding=utf-8 2 import matplotlib.pyplot as plt 3 4 decisionNode = dict(boxstyle='sawtooth', fc='10') 5 leafNode = dict(boxstyle='round4', fc='0.8') 6 arrow_args = dict(arrowstyle='<-') 7 8 9 def plotNode(nodeTxt, centerPt, parentPt, nodeType): 10 createPlot.ax1.annotate(nodeTxt, xy=parentPt, xycoords='axes fraction', \ 11 xytext=centerPt, textcoords='axes fraction', \ 12 va='center', ha='center', bbox=nodeType, arrowprops \ 13 =arrow_args) 14 15 16 def getNumLeafs(myTree): 17 numLeafs = 0 18 firstStr = list(myTree.keys())[0] 19 secondDict = myTree[firstStr] 20 for key in secondDict: 21 if (type(secondDict[key]).__name__ == 'dict'): 22 numLeafs += getNumLeafs(secondDict[key]) 23 else: 24 numLeafs += 1 25 return numLeafs 26 27 28 def getTreeDepth(myTree): 29 maxDepth = 0 30 firstStr = list(myTree.keys())[0] 31 secondDict = myTree[firstStr] 32 for key in secondDict: 33 if (type(secondDict[key]).__name__ == 'dict'): 34 thisDepth = 1 + getTreeDepth((secondDict[key])) 35 else: 36 thisDepth = 1 37 if thisDepth > maxDepth: maxDepth = thisDepth 38 return maxDepth 39 40 41 def retrieveTree(i): 42 # 预先设置树的信息 43 listOfTree = [] 44 return listOfTree[i] 45 46 47 def createPlot(inTree): 48 fig = plt.figure(1, facecolor='white') 49 fig.clf() 50 axprops = dict(xticks=[], yticks=[]) 51 createPlot.ax1 = plt.subplot(111, frameon=False, **axprops) 52 plotTree.totalW = float(getNumLeafs(inTree)) 53 plotTree.totalD = float(getTreeDepth(inTree)) 54 plotTree.xOff = -0.5 / plotTree.totalW; 55 plotTree.yOff = 1.0 56 plotTree(inTree, (0.5, 1.0), '') 57 plt.title('kaifeng.58.com\n') 58 plt.show() 59 60 61 def plotMidText(cntrPt, parentPt, txtString): 62 xMid = (parentPt[0] - cntrPt[0]) / 2.0 + cntrPt[0] 63 yMid = (parentPt[1] - cntrPt[1]) / 2.0 + cntrPt[1] 64 createPlot.ax1.text(xMid, yMid, txtString) 65 66 67 def plotTree(myTree, parentPt, nodeTxt): 68 numLeafs = getNumLeafs(myTree) 69 depth = getTreeDepth(myTree) 70 firstStr = list(myTree.keys())[0] 71 cntrPt = (plotTree.xOff + (1.0 + float(numLeafs)) / 2.0 / plotTree.totalW, \ 72 plotTree.yOff) 73 plotMidText(cntrPt, parentPt, nodeTxt) 74 plotNode(firstStr, cntrPt, parentPt, decisionNode) 75 secondDict = myTree[firstStr] 76 plotTree.yOff = plotTree.yOff - 1.0 / plotTree.totalD 77 for key in secondDict: 78 if type(secondDict[key]).__name__ == 'dict': 79 plotTree(secondDict[key], cntrPt, str(key)) 80 else: 81 plotTree.xOff = plotTree.xOff + 1.0 / plotTree.totalW 82 plotNode(secondDict[key], (plotTree.xOff, plotTree.yOff), \ 83 cntrPt, leafNode) 84 plotMidText((plotTree.xOff, plotTree.yOff), cntrPt, str(key)) 85 plotTree.yOff = plotTree.yOff + 1.0 / plotTree.totalD 86 87 88 if __name__ == '__main__': 89 myTree = retrieveTree(2) 90 createPlot(myTree) 构造信息: 1 [{'no surfacing': {0: 'no', 1: {'flipper': {0: 'no', 1: 'yes'}}}}, 2 {'no surfacing': {0: 'no', 1: {'flipper': {0: {'head': {0: 'no', 1: 'yes'}}, 1: 'no'}}}}, 3 {'House prices <= 2000': { 4 1: {'Room size >= 50': {1: 'Yes', 0: 'No'}}, 0: 'No'}}] 结果:

优秀的个人博客,低调大师

Python爬虫(二)——对开封市58同城出租房数据进行分析

出租房面积(area) 出租房价格(price) 对比信息 代码 1 import matplotlib as mpl 2 import matplotlib.pyplot as plt 3 import pandas as pad 4 import seaborn as sns 5 import numpy as np 6 7 sns.set_style('dark') 8 kf = pad.read_csv('kf.csv') 9 10 def sinplotone(): 11 fig,ax = plt.subplots() 12 ax.violinplot(kf['price']) 13 plt.show() 14 15 def sinplottwo(): 16 sns.set_style('whitegrid') 17 sns.boxplot(kf['price'],palette='deep') 18 # sns.despine(left=True) 19 plt.show() 20 21 def sinplotthree(): 22 sns.distplot(kf['price']) 23 plt.show() 24 25 def s(): 26 df = pad.DataFrame(kf['area'],kf['price']) 27 sns.jointplot(x='x',y='y',data=df) 28 plt.show() 29 30 if __name__ == '__main__': 31 fig,ax = plt.subplots() 32 ax.scatter(kf['area'],kf['price'],12) 33 plt.show()

优秀的个人博客,低调大师

Python网络爬虫之利用urllib2通过URL抓取网页内容

所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地。 类似于使用程序模拟IE浏览器的功能,把URL作为HTTP请求的内容发送到服务器端, 然后读取服务器端的响应资源。 一、通过urllib2抓取百度网页 在Python中,我们使用urllib2这个组件来抓取网页。urllib2是Python的一个获取URLs(Uniform Resource Locators)的组件。它以urlopen函数的形式提供了一个非常简单的接口。最简单的urllib2的应用代码只需要四行。 urllib2抓取百度网页 我们通过浏览器可以打开百度主页,右击,选择查看源代码(火狐OR谷歌浏览器均可),会发现也是完全一样的内容。也就是说,上面这四行代码将我们访问百度时浏览器收到的代码们全部打印了出来。这就是一个最简单的urllib2的例子。 当然,除了"http:",URL同样可以使用"ftp:","file:"等等来替代。HTTP是基于请求和应答机制的:客户端提出请求,服务端提供应答。 二、urllib结合Request用法 urllib2用一个Request对象来映射你提出的HTTP请求。在它最简单的使用形式中你将用你要请求的地址创建一个Request对象,通过调用urlopen并传入Request对象,将返回一个相关请求response对象,这个应答对象如同一个文件对象,所以你可以在Response中调用.read()客户端提出请求,服务端提供应答。 urllib+Request用法 可以看到,以上两种用法的输出结果都是一致的。 三、HTTP请求的同时传入参数data 设置Headers到http请求 有一些网站不喜欢被程序(非人为访问)访问,或者发送不同版本的内容到不同的浏览器。默认的urllib2把自己作为“Python-urllib/x.y”(x和y是Python主版本和次版本号,例如Python-urllib/2.7),浏览器确认自己身份是通过User-Agent头,当你创建了一个请求对象,你可以给他一个包含头数据的字典。 Headers请求HTTP

优秀的个人博客,低调大师

GEO技术实践:从AI爬虫、结构化数据到引用监测怎么做?

GEO(Generative Engine Optimization,生成式引擎优化)是针对生成式搜索与 AI 问答系统的发现、检索、理解、引用和展示链路,对公开网页的技术结构、信息组织和可验证性进行优化的方法。2023 年提出 GEO 概念的论文,将目标定义为提升内容在生成式引擎回答中的可见性。工程上更稳妥的理解是:提高网页“可抓取、可发现、可理解、可引用、可验证、可监测”的概率,而不是试图保证某个模型一定推荐某个页面。

优秀的个人博客,低调大师

爬虫调度系统设计:用 Celery 实现按媒体权重动态调整的抓取频率控制

做舆情采集的朋友大多遇到过这个两难:固定频率去抓全网媒体,要么低频漏掉突发热点,要么高频把代理流量烧光还被站点限流。我之前一套系统就是这么垮的——所有媒体一刀切每 5 分钟抓一次,结果低权重的边缘站点占了七成请求量,真正该盯紧的头部媒体反而因为代理配额被挤占,关键时刻没抓到关键稿件。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册