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 6672069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:27:53+00:00 2026-05-26T03:27:53+00:00

Trying to scrape the content off a site with Python, that has a simple

  • 0

Trying to scrape the content off a site with Python, that has a simple form authentication with username and password, but also has a hidden field called “foil” that contains what looks like a randomly generated string each time the page is loaded. In order to successfully login that value must be included in the content header of the post. I’ve tried scraping out the random string after the login page loads but still redirects me back to login. I have a valid username and password for the site that works, but it is update sporadically and I would like to send myself an email when something changes. here is the code i’ve been working with so far…

import urllib, urllib2, cookielib,subprocess

url='https://example.com/login.asp'

username='blah'
password='blah'

request = urllib2.Request(url)
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
preData = opener.open(request).readlines()
for line in preData:
    if("foil" in line):
        foils = line.split('"')
        notFoiled = foils[3]

query_args={'location':'','qstring':'','absr_ID':notFoiled,'id':username,'pin':password,'submit':'Sign In'}
requestWheader = urllib2.Request('https://example.com/login.asp')
requestWheader.add_data(urllib.urlencode(query_args))
print 'Request method after data :', requestWheader.get_method()

print
print 'OUTGOING DATA:'
print requestWheader.get_data()

print
print 'SERVER RESPONSE:'
print urllib2.urlopen(requestWheader).read()
rawRes = urllib2.urlopen(requestWheader).read()

The form looks like this…

<form name="loginform" method="post" action="https://example.com/login.asp?x=x&amp;&amp;pswd=">
<input type=hidden name="location" value="">
<input type=hidden name="qstring" value="">
<input type=hidden name="absr_ID" value="">
<input type=hidden name="foil" value="91fcMO">
<input type="text" name="id" maxlength="80" size="21" value="" mask="" desc="ID" required="true">
<input type="submit" name="submit" value="Sign In" onClick="return checkForm(loginform)">
<input type="password" name="pin" size="6" maxlength="6" desc="Pin" required="true">
  • 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-26T03:27:53+00:00Added an answer on May 26, 2026 at 3:27 am

    You import cookielib but it does not seem like you’re using any CookieJars:

    jar = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
    

    Then use the same opener for both initial form fetching and login form submission. I assume it’s a cookie-based protection where a value that comes from the foil field has to match a cookie that comes in the headers.

    Another thing I noticed in your code is that you assign notFoiled to absr_ID instead of foil. Was that intentional?

    Also please do yourself a favor and use html5lib or BeautifulSoup instead of parsing HTML manually.

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

Sidebar

Related Questions

I'm trying to scrape some content off another site and I'm not sure why
Trying out mechanize to scrape some content off an https asp site, it looks
I'm trying to scrape a span element that has mixed content <span id=span-id> <!--starts
I'm currently trying to scrape a website that has fairly poorly-formatted HTML (often missing
I'm trying to scrape a page but the initial response has nothing in the
Hey can someone help with the following? I'm trying to scrape a site that
The site that I'm trying to scrape uses js to create a cookie. What
I'm trying to scrape a webpage using Selenium (in Python) that is almost entirely
I am trying to scrape an ASP.NET website but am having trouble getting the
There are many tools that scrape HTML pages with javascript off, however are there

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.