栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何抓取需要首先使用Python登录的网站

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何抓取需要首先使用Python登录的网站

这对我有用:

##################################### Method 1import mechanizeimport cookielibfrom BeautifulSoup import BeautifulSoupimport html2text# Browserbr = mechanize.Browser()# cookie Jarcj = cookielib.LWPcookieJar()br.set_cookiejar(cj)# Browser optionsbr.set_handle_equiv(True)br.set_handle_gzip(True)br.set_handle_redirect(True)br.set_handle_referer(True)br.set_handle_robots(False)br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)br.addheaders = [('User-agent', 'Chrome')]# The site we will navigate into, handling it's sessionbr.open('https://github.com/login')# View available formsfor f in br.forms():    print f# Select the second (index one) form (the first form is a search query box)br.select_form(nr=1)# User credentialsbr.form['login'] = 'mylogin'br.form['password'] = 'mypass'# Loginbr.submit()print(br.open('https://github.com/settings/emails').read())

你一点也不远!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/638636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号