python模拟登录及表单提交 (非原创,拷贝caleng的)
来源:互联网 发布:android保存数据方式 编辑:程序博客网 时间:2024/05/22 04:59
# -*- coding: utf-8 -*-
import re
import urllib
import urllib2
import cookielib
#获取CSDN博客标题和正文
url = "http://blog.csdn.net/[username]/archive/2010/07/05/5712850.aspx"
sock = urllib.urlopen(url)
html = sock.read()
sock.close()
content = re.findall('(?<=blogstory">).*(?=<p class="right artical)', html, re.S)
content = re.findall('<mce:script.*><!--
.*
// --></mce:script>(.*)', content[0], re.S)
title = re.findall('(?<=<title>)(.*)-.* - CSDN.*(?=</title>)', html, re.S)
#根据上文获取内容新建表单值
blog = {'spBlogTitle': title[0].decode('utf-8').encode('gbk'), #百度博客标题
'spBlogText': content[0].decode('utf-8').encode('gbk'),#百度博客内容
'ct': "1",
'cm': "1"}
del content
del title
#模拟登录
cj = cookielib.CookieJar()
#用户名和密码
post_data = urllib.urlencode({'username': '[username]', 'password': '[password]', 'pwd': '1'})
#登录路径
path = 'https://passport.baidu.com/?login'
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Opera/9.23')]
urllib2.install_opener(opener)
req = urllib2.Request(path, post_data)
conn = urllib2.urlopen(req)
#获取百度发布博客的认证令牌
bd = urllib2.urlopen(urllib2.Request('http://hi.baidu.com/[username]/creat/blog')).read()
bd = re.findall('(?<=bdstoken/" value=/").*(?=ct)', bd, re.S)
blog['bdstoken'] = bd[0][:32]
#设置分类名
blog['spBlogCatName'] = 'php'
#比较表单发布博客
req2 = urllib2.Request('http://hi.baidu.com/[username]/commit', urllib.urlencode(blog))
#查看表单提交后返回内容
print urllib2.urlopen(req2).read()
#请将[username]/[password]替换为您的真实用户名和密码
#搞定收工……
import re
import urllib
import urllib2
import cookielib
#获取CSDN博客标题和正文
url = "http://blog.csdn.net/[username]/archive/2010/07/05/5712850.aspx"
sock = urllib.urlopen(url)
html = sock.read()
sock.close()
content = re.findall('(?<=blogstory">).*(?=<p class="right artical)', html, re.S)
content = re.findall('<mce:script.*><!--
.*
// --></mce:script>(.*)', content[0], re.S)
title = re.findall('(?<=<title>)(.*)-.* - CSDN.*(?=</title>)', html, re.S)
#根据上文获取内容新建表单值
blog = {'spBlogTitle': title[0].decode('utf-8').encode('gbk'), #百度博客标题
'spBlogText': content[0].decode('utf-8').encode('gbk'),#百度博客内容
'ct': "1",
'cm': "1"}
del content
del title
#模拟登录
cj = cookielib.CookieJar()
#用户名和密码
post_data = urllib.urlencode({'username': '[username]', 'password': '[password]', 'pwd': '1'})
#登录路径
path = 'https://passport.baidu.com/?login'
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Opera/9.23')]
urllib2.install_opener(opener)
req = urllib2.Request(path, post_data)
conn = urllib2.urlopen(req)
#获取百度发布博客的认证令牌
bd = urllib2.urlopen(urllib2.Request('http://hi.baidu.com/[username]/creat/blog')).read()
bd = re.findall('(?<=bdstoken/" value=/").*(?=ct)', bd, re.S)
blog['bdstoken'] = bd[0][:32]
#设置分类名
blog['spBlogCatName'] = 'php'
#比较表单发布博客
req2 = urllib2.Request('http://hi.baidu.com/[username]/commit', urllib.urlencode(blog))
#查看表单提交后返回内容
print urllib2.urlopen(req2).read()
#请将[username]/[password]替换为您的真实用户名和密码
#搞定收工……
0 0
- python模拟登录及表单提交 (非原创,拷贝caleng的)
- python模拟登录及表单提交
- Python 模拟登录及表单提交
- python模拟登录及表单提交
- python模拟登录及表单提交
- Python模拟表单提交登录广工图书馆
- 用python模拟提交表单
- 模拟页面(表单)提交登录
- [原创]jquery form表单提交及验证
- 模拟表单提交的例子
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- php+Angularjs 实现Post 提交表单 模拟登录
- extjs表单的非ajax提交方式
- Android简单的web提交表单登录
- PHP模拟表单提交
- VC++ 模拟表单提交
- HttpClient4模拟表单提交
- 你于我的一种安宁
- Android 获取手机存储空间
- Android中从源码分析关于AsyncTask的使用
- 【C语言】10-字符和字符串常用处理函数
- static_cast和reinterpret_cast
- python模拟登录及表单提交 (非原创,拷贝caleng的)
- 如何在CSDN博客添加友情链接
- 一些经典的计算机书籍
- 正则表达式入门教程
- 有关django权限管理的文章
- SVG在WEB绘图中的使用
- 打开Editor的几种方式
- 又是星期一。继续Ranorex
- POJ 3723 Conscription