在理解了LNMPA框架,读懂了LNMPA一键安装的shell脚本后,在虚拟机安装好LNMPA环境,包括phpmyadmin。因为自己搭建的环境比较简单,首先利用phpmyadmin来模拟爬虫登陆。直接上代码。
#!/usr/bin/env python #-*-coding:utf-8 -*- __author__ = "PS" """ python version : 2.7.9 """ import urllib import urllib2 import cookielib cookie = cookielib.MozillaCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) login_url = ‘http://172.18.216.205/phpmyadmin/index.php‘ values = {‘pma_username‘:‘root‘,‘pma_password‘:‘xxx‘} postdata = urllib.urlencode(values) user_agent = ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36‘ headers = {‘User-Agent‘:user_agent} request = urllib2.Request(login_url,postdata,headers) response = opener.open(request) print response.read()
本文出自 “新手PS欢迎交流” 博客,请务必保留此出处http://linpeisong.blog.51cto.com/9601554/1743367
原文地址:http://linpeisong.blog.51cto.com/9601554/1743367