python programm to log into the web page

后端 未结 2 2244
梦如初夏
梦如初夏 2021-01-29 14:45

Does anyone knows what\'s wrong in this code ? When I run it I get same HTML page back.

# -*- coding: utf-8 -*-

from http import cookiejar
import urllib.reques         


        
2条回答
  •  耶瑟儿~
    2021-01-29 15:22

    Login into a web applicaction by script may be trivial or awfully complex, depending on how the login page is organized. In my experience, the only foolproof way is :

    • use a network spy like wireshark
    • spy a full successful login sequence from a true browser
    • until successful loop :
      • try to reproduce it with the script
      • spy the login sequence from the script and analyze differences

    IMHO using urllib2 or requests make little differences. The only tool that is much better at that would be mechanize, but unfortunately it seems not to be ported to Python 3

提交回复
热议问题