python爬虫之登录
2023-09-27 14:29:13 时间
#-*-coding:utf-8-*- import cookielib, urllib, urllib2 import json import threading,time class Order(object): ########## login def __init__(self): print "init" def speak(self): count = 300 url = "http://zweb.com/login" data='{"email":"a@test.com", "password":"***"}' # jdata = json.dumps(data) # post_data=urllib.urlencode(jdata) headers ={'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 8.1)','Acc ept-Encoding': 'gzip, deflate','Connection':'keep-alive'} ckjar = cookielib.MozillaCookieJar('./cookie.txt2') opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(ckjar)) req=urllib2.Request(url,data,headers) req.add_header('Content-Type', 'application/json') result = opener.open(req) htm = result.read() print htm ckjar.save(ignore_discard=True, ignore_expires=True) url = "http://zhweb.kingsoft.com/foodBookingOrders" data = {"foodBookingPlanId":95,"items":[{"planItemId":311},{"planItemId":309},{" planItemId":308}]} jdata = json.dumps(data) headers ={'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 8.1)','Acc ept-Encoding': 'gzip, deflate','Connection':'keep-alive'} while count >= 0: req=urllib2.Request(url,jdata) # req.add_header('Content-Type', 'text/plain;charset=UTF-8') req.add_header('Content-Type', 'application/json') result = opener.open(req) htm = result.read() print htm file_object = open('./out.txt', 'a') file_object.write(htm) file_object.close( ) time.sleep(1) count=count - 1 ########## if __name__ == "__main__": p = Order() p.speak() #count = 1 #while count > 0: # timer = threading.Timer(5, p.speak(), (p,)) # print "start" # timer.start() # timer.join() # print "after join" # count=count - 1 # timer.cancel()
相关文章
- Python爬虫之-动态网页数据抓取
- Python爬虫之 正则表达式和re模块
- python爬虫知识点总结(十二)使用Redis和Flask维护动态代理池
- python爬虫知识点总结(九)Requests+正则表达式爬取猫眼电影
- 【华为OD机试真题 python】 We Are A Team【2022 Q4 | 100分】
- Google Earth Engine(GEE)——geemap介绍(PYTHON API)
- 请问到底如何学习python才好【建议收藏】
- Matplotlib for Python Developers
- 《精通Python网络爬虫:核心技术、框架与项目实战》——第二篇 Part 2核心技术篇 第3章 网络爬虫实现原理与实现技术 3.1 网络爬虫实现原理详解
- 《精通Python网络爬虫:核心技术、框架与项目实战》——3.7 实例——metaseeker
- python scrapy爬虫框架
- Python爬虫技术--基础篇--电子邮件
- Python爬虫技术--基础篇--内建模块itertools,contextlib和urllib
- Python爬虫技术--基础篇--进程 vs. 线程和分布式进程
- Python爬虫入门实战项目——彼岸图网
- Python爬虫技术--基础篇--输入与输出语句
- python网络爬虫 - 如何伪装逃过反爬虫程序
- Python网络爬虫 - 1. 准备工作
- python自学篇——PyGame模块的所有功能函数详解
- 输入一个字符串,打印出该字符串中字符的所有排列-python
- 《Python数据科学指南》——1.16 使用lambda创造匿名函数
- Python爬虫入门一之综述
- Python代码库OpenCV之10圆检测circle detection 霍夫曼(含代码)
- python爬虫入门(六) Scrapy框架之原理介绍
- Python实现空间直角坐标转高斯克吕格平面坐标
- Python 爬虫 之 爬虫的一些基本知识和基本操作(爬取视频、图片、获取网页源码等)整理
- Python 爬虫 之 Selenium 模拟打开操作浏览器爬取斗鱼全部视播相关信息,并json保存信息
- 【Python爬虫】:模拟登录QQ空间
- Python爬虫爬取糗事百科热文