Python uses mechanize to login Sina email

Source: Internet
Author: User
Mechanize Related Knowledge Preparation:

mechanize.Browser()<br># 设置是否处理HTML http-equiv标头

set_handle_equiv(True)<br># 设置是否处理重定向

set_handle_redirect(True)<br># 设置是否向每个请求添加referer头

set_handle_referer(True)<br># 设置是不遵守robots中的规则

set_handle_robots(False)<br># 处理giz传输编码

set_handle_gzip(False)<br># 设置浏览器的头部信息

The login code is as follows:


Import Mechanizebr=mechanize. Browser () br.set_handle_robots (False) #表示不遵循robots中的规则url = ' http://mail.sina.com.cn/' br.addheaders = [(' User-agent ' , ' * ')]br.open (URL) for form in Br.forms (): #查看登录页面中的表单    print Formbr.select_form (nr=0) br[' local ']= ' user name ' br[' pwd ']= ' Password ' response=br.submit () print ' success ' for link in br.links ():    print link.url+ ': ' +link.text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.