# -*-coding:utf8-*-
import urllib2
from lxml import etree
import re
import requests
import os
import json
os.chdir(u'马克思')
UserAgent='Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36'
Referer='http://bb.hebeinu.edu.cn/webapps/portal/execute/tabs/tabAction?tab_tab_group_id=_1_1'
cookies={'Cookie':'JSESSIONID=CFEC201E8125FAB2ABE45B3CBA0C7DF4.root; safedog-flow-item=26254C650DE73224ABE3352E70B047C7; JSESSIONID=DF055DD45AC6387DE2DBB2ACEE399445.root; session_id=91BA1E31EFF1DAAA7D881BC2561E79CA'}
headers={'User-Agent':UserAgent,'Referer':Referer}
url="http://bb.hebeinu.edu.cn/webapps/assessment/review/review.jsp?attempt_id=_121777_1&course_id=_1676_1&content_id=_35847_1&return_content=1&step=null&refreshCourseMenu=true"
def getcontent():
html=requests.get(url,cookies=cookies).content
print html
reg=re.compile(r'<div tabindex="0">s([sS]*?)s</table>')
content= re.findall(reg,html)
p=0
fd=open(u'第二章多选题.txt','wb')
for i in content:
p+=1
fd.write('%s.'%p)
print '%s.'%p
#qu= re.findall(r'<div class="vtbegenerated inlineVtbegenerated">(.*?)</div>',i)[0]
ans= re.findall(r'<div class="vtbegenerated inlineVtbegenerated">(.*?)</div>',i)
for m in ans:
fd.write(m+'
')
print m
fd.close()
每次登陆cookies的值都会改变
注意保存时应用
作为换行