首页 > 编程语言 > 详细

python3 爬虫小例子

时间:2014-07-21 08:22:19      阅读:485      评论:0      收藏:0      [点我收藏+]

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys,re
import urllib.request,urllib.parse,http.cookiejar

class myW3():
    def login(self):
        ‘post 数据‘
        data = {"uid":self.uid,‘password‘:self.password,‘actionFlag‘:‘loginAuthenticate‘}
        
        user_agent=‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)‘
        postData = urllib.parse.urlencode(data)
        postData = postData.encode(encoding=‘utf_8‘)
        headers = {‘User-Agent‘:user_agent}
        request = urllib.request.Request(self.url, postData,headers)
        urllib.request.urlopen(request).read().decode(‘utf-8‘)
    def cookie(self):
        ‘‘‘设置cookie,非常重要‘‘‘
        cj = http.cookiejar.CookieJar()
        cp = urllib.request.HTTPCookieProcessor(cj)
        opener = urllib.request.build_opener(cp)
        urllib.request.install_opener(opener)
    def __init__(self,uid = None,password=None,url=None):
        if uid is None or password is None:
            sys.exit(1)
        self.uid = uid
        self.password = password
        self.url = url
        self.count = 0
        self.cookie()
        self.login()

python3 爬虫小例子,布布扣,bubuko.com

python3 爬虫小例子

原文:http://www.cnblogs.com/orientwolf/p/3857480.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!