好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python多线程抓取*子内容示例

使用re, urllib, threading 多线程抓取天涯帖子内容,设置url为需抓取的天涯帖子的第一页,设置file_name为下载后的文件名

代码如下:


#coding:utf-8

import urllib
import re
import threading
import os, time

class Down_Tianya(threading.Thread):
"""多线程下载"""
def __init__(self, url, num, dt):
threading.Thread.__init__(self)
self.url = url
self.num = num
self.txt_dict = dt

def run(self):
print 'downling from %s' % self.url
self.down_text()

def down_text(self):
"""根据传入的url抓出各页内容,按页数做键存入字典"""
html_content =urllib.urlopen(self.url).read()
text_pattern = re测试数据pile(' 时间:(.*?) .*? 楼主

查看更多关于python多线程抓取*子内容示例的详细内容...

  阅读:34次