import urllib,urllib2,httplib,cookielib
def auto_login_hi(url,name,pwd):
url_hi="http://passport.baidu.com/?login"
#设置cookie
cookie=cookielib.CookieJar()
cj=urllib2.HTTPCookieProcessor(cookie)
#设置登录参数
postdata=urllib.urlencode({'username':name,'password':pwd})
#生成请求
request=urllib2.Request(url_hi,postdata)
#登录百度
opener=urllib2.build_opener(request,cj)
f=opener.open(request)
print f
#打开百度HI空间页面
hi_html=opener.open(url)
return hi_html
if __name__=='__main__':
name='name'
password='password'
url='yoururl'#例如:url='http://hi.baidu.com/cdkey51'
h=auto_login_hi(url,name,password)
print h.read()#h里面的内容便是登录后的页面内容
基于文本文档(Markdown) 设想好需要的基本需要的表、字段、类型;使用 Rails Migration 随着功能的开发逐步创建表;
随着细节功能的开发、需求,逐步增加字段,删除字段,或者调整字段类型;
第一个 Release 的时候清理 Migrations 合并成一个
随着后期的改动,逐步增加、修改、删除字段或表。
基本上我的所有项目都是这么搞的,这和项目是否复杂无关。
所以我前面为什么说思路需要转变。
爬虫跟踪下一页的方法是自己模拟点击下一页连接,然后发出新的请求。请看: item1 = Item()yield item1item2 = Item()yield item2req = Request(url='下一页的链接', callback=self.parse)yield req 注意使用yield时不要用return语句。