65 Star 350 Fork 182

耿直的小爬虫 / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
模拟登陆(保存cookies) 975 Bytes
一键复制 编辑 原始数据 按行查看 历史
import urllib.request as r
import urllib.parse as p
import http.cookiejar as c
url='http://bbs.chinaunix.net/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LxogS'
postdata=p.urlencode({
#username password自己加上 没有在这个网站上注册的话 就先去注册一个
'username':' ',
'password':' '
}).encode('utf-8')
req=r.Request(url,postdata)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0')
cjar=c.CookieJar()
opener=r.build_opener(r.HTTPCookieProcessor(cjar))
r.install_opener(opener)
file=opener.open(req)
data=file.read()
with open('1.html','wb')as p:
print('data是什么类型的:',type(data))
p.write(data)
print('1.html爬取完毕')
url2='http://bbs.chinaunix.net/'
data2=r.urlopen(url2).read()
with open('2.html','wb')as b:
b.write(data2)
print('2.html爬取完毕')
Python
1
https://gitee.com/testp2y/python_reptilian.git
git@gitee.com:testp2y/python_reptilian.git
testp2y
python_reptilian
Python爬虫
master

搜索帮助