Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:31:33+00:00 2026-05-25T20:31:33+00:00

I have an almost working code to connect to a server and do a

  • 0

I have an almost working code to connect to a server and do a search. But there is some issue here with the code. This is what I do now with the following python script. I login to the site. Construct a url for the search result and access the search page and open it in a browser. But issue I am facing here is that I am getting a session expired page. But if I have a logged in page open(manually) in the browser, this constructed url is giving me the desired output. So my question here is that How can I keep the ‘logged in’ session in the script active and open the constructed url in a browser which yield me the desired output.

#!/usr/bin/env python

import urllib, urllib2, cookielib, mechanize, webbrowser, subprocess
from mechanize import ParseResponse, urlopen, urljoin

def main():
    usr = 'sg092350'
    pwd = 'gk530911'
    login_url = 'http://int15.sla.findhere.net/logininq.act?&site=superarms'

    search_url_1 = '&need_air=yes&need_rail=no&need_train=no&need_hotel=no&need_car=no&origin_request=regular+booking&monAbbrList[0]=9&monAbbrList[1]=9&dateList[0]=29&dateList[1]=30&pickUpCity=&pickUpTime=&dropOffCity=&dropOffTime=&dispAOptions=&dispADestinations=&checkSurroundingAirports=false&doEncodeDecodeForSurrArpt=false&checkPlusMinusDays=N&tripType=roundTrip&itinType=on&departList[0]=BLR&destinationList[0]=DEL&date0=9%2F29%2F11&travelMethodList[0]=departs&timeList[0]=8&date1=9%2F30%2F11&travelMethodList[1]=departs&timeList[1]=8&numPassengers=1&cabinClass=1&pricingType=1&preferredCarrier[0]=&preferredCarrier[1]=&preferredCarrier[2]=&userRequestedWebFares=true'



    br = mechanize.Browser()
    cj = cookielib.CookieJar()

    br.set_cookiejar(cj)
    br.set_handle_robots(False)

    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2')]

    br.open(login_url)
    br.select_form('loginForm')

    br.form['user'] = usr
    br.form['pwd'] = pwd

    br.submit()
    print br.geturl()

    response = urlopen(login_url)
    forms = ParseResponse(response, backwards_compat=False)
    form = forms[0]
    token = forms[0]['token']
    site_id = forms[0]['siteID']
    site = forms[0]['site']
    water_mark = forms[0]['watermark']
    trans_index = forms[0]['transIndex']


    search_url_0 = 'http://int15.sla.findhere.net/pwairavail.act;' + '?site=' + site + '&sid=4' + '&siteID=' + site_id + '&watermark=' + water_mark + '&token=' + token + '&transIndex=' + trans_index + search_url_1
    print search_url_0

    print token
    print site_id
    print site
    print water_mark
    print trans_index

    print form

    response.read()

    #Inserting code to generate html and display the overlay

    htmlString = """
    <html>
    <head>
    <title>DirectBook 1.0</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript" src="./fx/jquery.fancybox-1.3.4.pack.js"></script>
    <link rel="stylesheet" type="text/css" href="./fx/jquery.fancybox-1.3.4.css" media="screen"/>
    <script type="text/javascript">
    $(document).ready(function() {
    $("#urlLink").fancybox
    ({
    'width'      : '100%',
    'height'      : '100%',
    'autoScale'      : false,
    'transitionIn'   : 'fade',
    'transitionOut'   : 'fade',
    'type'      : 'iframe'
    });
    });
    </script>
    </head>
    <body onload="document.getElementById('urlLink').click()">
    <div id="content">
    <script type="text/javascript">
    var search_url = " """ + search_url_0 + """ ";
    document.write('<a id="urlLink"' + 'href="' + search_url + '"></a>');
    </script>
    </div>
    </body>
    </html>"""


    # write the html file to the working folder
    fout = open("search.html", "w")
    fout.write(htmlString)
    fout.close()

    subprocess.Popen('"C:\\Program Files\\Mozilla Firefox\\firefox.exe" "C:\\Python27\\mechanize-0.2.5\\search.html"')


if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:31:34+00:00Added an answer on May 25, 2026 at 8:31 pm

    You need to share the session (or session identifier, which is probably stored in a cookie) between Mechanize and your browser. This is not easy, and definitely not portable between browsers (if you want that).

    However, there appears to be support in Mechanize for the SQLite database format that Firefox uses since version 3:
    https://github.com/jjlee/mechanize/blob/master/mechanize/_firefox3cookiejar.py

    You may want to check the documentation for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have working code below for collision of two circles, but now I have
I almost have the thing working but I can't get past a parsing issue.
I write server code but have little to almost no JQ experience. I have
I almost have facebook connect working the way I need it on my site,
I almost have this working however the script is rounding my numbers while I
I have QuickLook (QLPreviewController) almost working how I want it, but because of the
I already have this almost working, with a neat snippet someone helped me with.
I have 5 spinners which are almost working perfectly, there is just one little
I am about to start a web project and have been working almost exclusively
Some development skills, like refactoring operations, feel like they have an almost unlimited pontential

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.