Import Requests from BS4 Import BeautifulSoup # 1. access to the landing page for authenticity_token I1 = requests.get ( ' https://github.com/login ' ) soup1 = BeautifulSoup (i1.text, Features = ' html.parser ' ) Tag soup1.find = (name = ' INPUT ' , attrs = { ' name ' : ' authenticity_token ' }) authenticity_token = tag.get ( ' value ' ) # acquires cookie first visit c1 =i1.cookies.get_dict () i1.close () # 1. carries information authenticity_token password and user name, user authentication sent form_data = { " authenticity_token " : authenticity_token, " UTF8 " : "" , " the commit " : " Sign in " , " Login " : " [email protected] " , ' password ' : ' XXOO ' } I2 = requests.post ( 'https://github.com/session' , Data = form_data, Cookies = C1) # Get the second Cookie C2 = i2.cookies.get_dict () # obtain the second cookie + acquired second time Cookie c1.update (C2) # I3 = Requests .get ( ' https://github.com/settings/repositories ' , Cookies = C1) soup3 = the BeautifulSoup (i3.text, Features = ' html.parser ' ) list_group = soup3.find (name = ' div ' , the class_ = ' listgroup ' ) from bs4.element Import the Tag for Childin list_group.children: if isinstance(child, Tag): project_tag = child.find(name='a', class_='mr-1') size_tag = child.find(name='small') temp = "项目:%s(%s); 项目路径:%s" % (project_tag.get('href'), size_tag.string, project_tag.string, ) print(temp)
Example: know almost automatic login
Guess you like
Origin www.cnblogs.com/jintian/p/11403226.html
Recommended
Ranking