精通Python自然语言处理pdf免费下载
ÎÒÃÇÒÔѧÐÅÍøÎªÀýÅÀÈ¡¸öÈËÐÅÏ¢
**Èç¹û¿´²»Çå³þ
°´ÕÕÒÔϲ½Ö裺**
1.»ðºüΪÀý ´ò¿ªÐèÒªµÇ¼µÄÍøÒ³¨C> F12 ¿ª·¢Õßģʽ £¨Êó±êÓÒ»÷£¬µã»÷¼ì²éÔªËØ£©¨Cµã»÷ÍøÂç ¨C>ÐèÒªµÇ¼µÄÒ³ÃæµÇ¼Ï¨C> µã»÷ÍøÂçÕÒµ½ Ò»¸öPOSTÌá½»µÄÁ´½Óµã»÷¨C>ÕÒµ½post£¨×¢Òâ¸ÃpostÖÐÐÅÏ¢¾ÍÊÇÎÒÃÇÌύʱÐèÒª¹¹ÔìµÄ±íµ¥ÐÅÏ¢£©

import requests
from bs4 import BeautifulSoup
from http import cookies
import urllib
import http.cookiejar
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0',
'Referer':'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check',
}
session = requests.Session()
session.headers.update(headers)
username = 'xxx'
password = 'xxx'
url = 'https://account.chsi.com.cn/passport/login?service=https://my.chsi.com.cn/archive/j_spring_cas_security_check'
def login(username,password,lt,_eventId='submit'): #Ä£ÄâµÇÈ뺯Êý
#¹¹Ôì±íµ¥Êý¾Ý
data = { #ÐèÒª´«È¥µÄÊý¾Ý
'_eventId':_eventId,
'lt':lt,
'password':password,
'submit':u'怬',
'username':username,
}
html = session.post(url,data=data,headers=headers)
def get_lt(url): #½âÎöµÇÈë½çÃæ_eventId
html = session.get(url)
#»ñÈ¡ lt
soup = BeautifulSoup(html.text,'lxml',from_encoding="utf-8")
lt=soup.find('input',type="hidden")['value']
return lt
lt = get_lt(url)#»ñÈ¡µÇ¼form±íµ¥ÐÅÏ¢ ÒÔѧÐÅÍøÎªÀý
login(username,password,lt)
login_url = 'https://my.chsi.com.cn/archive/gdjy/xj/show.action'
per_html = session.get(login_url)
soup = BeautifulSoup(per_html.text,'lxml',from_encoding="utf-8")
print(soup)
for tag in soup.find_all('table',class_='mb-table'):
print(tag)
for tag1 in tag.find_all('td'):
title= tag1.get_text();
print(title)
ÒÔÉÏÕâÆªpython ÅÀȡѧÐÅÍøµÇÂ¼Ò³ÃæµÄÀý×Ó¾ÍÊÇС±à·ÖÏí¸ø´ó¼ÒµÄÈ«²¿ÄÚÈÝÁË£¬Ï£ÍûÄܸø´ó¼ÒÒ»¸ö²Î¿¼£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö½Å±¾Ö®¼Ò¡£
转载请注明:谷谷点程序 » python 爬取学信网登录页面的例子