中企动力 > 头条 > python有多强大

网站性能检测评分

注:本网站页面html检测工具扫描网站中存在的基本问题,仅供参考。

python有多强大

Python大牛分分钟成功爬取电影天堂网站!厉害了!「附源码」 公司视频课程

img

待消磨

关注

准备工具:requests与xpath

思路:获取爬取入口,后面的工作就容易多了。我通过测试发现这几个栏目除了页面的 url地址不一样之外,提取信息的xpath路径是一样的!所以,我们把五个栏目当做一个类,然后该类进行遍历爬取!

2.2爬虫构架的设计

2.3代码

#截止到2017-08-08,最新电影一共才有 164个页面LASTEST_MOIVE_TOTAL_SUM = 6 #164#请求网络线程总数,线程不要调太好,不然会返回很多 400THREAD_SUM = 5def startSpider: #实例化对象 #获取【最新电影】有多少个页面 LASTEST_MOIVE_TOTAL_SUM = dytt_Lastest.getMaxsize print('【最新电影】一共 ' + str(LASTEST_MOIVE_TOTAL_SUM) + '有个页面') dyttlastest = dytt_Lastest(LASTEST_MOIVE_TOTAL_SUM) floorlist = dyttlastest.getPageUrlList floorQueue = TaskQueue.getFloorQueue for item in floorlist: floorQueue.put(item, 3) # print(floorQueue.qsize) for i in range(THREAD_SUM): workthread = FloorWorkThread(floorQueue, i) workthread.start while True: if TaskQueue.isFloorQueueEmpty: break else: pass

源码:

强大的Python:完全用Python工作 行业视频课程

img

张问旋

关注

主要内容:

1.代码简洁性和可读性2.Python的思想3.Python的类库齐全

下载:http://51testing/html/54/n-3720754.html

img

在线咨询

建站在线咨询

img

微信咨询

扫一扫添加
动力姐姐微信

img
img

TOP