Python Forum
HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button
#2
I think you need a Session. No problem, requests have this already.
First create a session object, then get the login page:

session = requests.Session()
response = session.get('http://192.168.192.1/cgi-bin/status.cgi') # in my case
# then you look in response.text for a form, there is an action and it's value is the url based
# on the current path you're on, in my case i used BeatifulSoup to find it.
# but you can use also a webbrowser
# <form action="sendResult.cgi?section=login" id="mainForm" method="post">
# <input name="loginDelay" type="hidden" value="0"/>
# <input name="page" type="hidden" value="login"/>
# <div>Benutzername</div>
# <input name="username" tabindex="1" type="text"/>
# <div>Passwort</div>
# <input name="password" tabindex="2" type="password"/>
# </form>

# so we need something to prepare the data for the form
# all fields should be submitted, also the hidden fields
# with requests you can just use a dict for this task
login = {'loginDelay': '0', 'page': 'login', 'username': 'admin', 'password': 'admin'}

# then you have to use the post method together with the target (action url) and
# login data
response = session.post('http://192.168.192.1/cgi-bin/sendResult.cgi?section=login', data=login)
if response.status_code == 200:
    print('Success')
    print(response.text)
For further webscraping you should use Beautiful Soup or Scrapy.
You can use also regex, but this is more complicated.

For full help, you've to post the whole html code. Without this we can only guess. I think it's still a form on your side wrapped around with javascript for the fancy stuff.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button - by DeaD_EyE - Jul-30-2017, 01:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cant click button by script at page michael1834 1 1,080 Dec-08-2023, 04:44 PM
Last Post: SpongeB0B
  Click on a button on web page using Selenium Pavel_47 7 4,728 Jan-05-2023, 04:20 AM
Last Post: ellapurnellrt
  POST requests - different requests return the same response Default_001 3 1,957 Mar-10-2022, 11:26 PM
Last Post: Default_001
  Show HTML in Python application and handle click SamHobbs 2 2,746 Sep-28-2021, 06:27 PM
Last Post: SamHobbs
  Login and download an exported csv file within a ribbon/button in a website Alekhya 0 2,672 Feb-26-2021, 04:15 PM
Last Post: Alekhya
  button click error rafarangel 2 3,139 Feb-11-2021, 08:19 PM
Last Post: buran
  Problem with logging in on website - python w/ requests GoldeNx 6 5,349 Sep-25-2020, 10:52 AM
Last Post: snippsat
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 3,843 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Python Webscraping with a Login Website warriordazza 0 2,610 Jun-07-2020, 07:04 AM
Last Post: warriordazza
  How to click facebook message button JanelleGuthrie 2 2,423 May-14-2020, 06:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020