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

  • SEARCH
  • Home
  • 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 8960293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:37:54+00:00 2026-06-15T15:37:54+00:00

I’m relatively new to python so things like this are not coming easy to

  • 0

I’m relatively new to python so things like this are not coming easy to me.

I just want to loop through a web pages content and then print each occurrence to the console window for now but I obviously have my loop wrong.

import sys
import re
import urllib2
import urlparse

crawling = tocrawl.pop()
response = urllib2.urlopen(crawling)

msg = response.read()
endDiv = msg.find('</div>')
while endDiv != -1:
    endDiv = msg.find('</div>')
    startPos = msg.find('class="facultyname">', endDiv)
    if startPos != -1:
        nextPos = msg.find('.php">', startPos)
        endPos = msg.find('</a>', nextPos)
    if endPos != -1:
        name = msg[nextPos+6:endPos]
        print name, "   ",

    startPos = msg.find('function escramble()')
    if startPos != -1:
        nextPos = msg.find('b=', startPos)
        endPos = msg.find('c', nextPos)
    if endPos != -1:
        email = msg[nextPos+3:endPos-1]
        email = email[:-13] + '@email.com'
        print email

    endDiv = msg.find('</div>', endPos)

I’m already grabbing the first occurrence, I just want to loop until the end of the page and collect the rest.

Sample HTML:

<div id="main-text">

   <p class="title">Research Scientists</p>


   <div class="space">&nbsp;</div>
   <img src="photos/icons/bastolaicon.jpg" class="faculty" width="53" height="71" alt="Bastola Photo" />

   <div class="facultyname">
     <strong><a href="people/bastola.php">person1</a>
     <br /><em>Post-Doctoral Scientist</em></strong>
     <br />
   </div>

   <div class="facultybody">
     Rm. 218A
     <br /><em><script type="text/javascript">

       <!--
       function escramble(){
       var a,b,c,d,e,f,g,h,i
       a='<a href=\"mai'
       b='person1'
       c='\">'
       a+='lto:'
       b+='@'
       e='</a>'
       f=''
       b+='email.com'
       g='<img src=\"'
       h=''
       i='\" alt="Email us." border="0">'

       if (f) d=f
       else if (h) d=g+h+i
       else d=b

       document.write(a+b+c+d+e)
       }
       escramble()
       //-->

       </script></em>

   </div>

   <div class="space">&nbsp;</div>

   <img src="photos/icons/person2icon.jpg" class="faculty" width="53" height="71" alt="person2 Photo" />

   <div class="facultyname">
     <strong><a href="people/person2.shtml">person2</a>
     <br /><em>Assistant Research Scientist</em></strong>
     <br />
   </div>

   <div class="facultybody">
     Rm. 227
     <br />(850) 645-1253
     <br /><em><script type="text/javascript">

       <!--
       function escramble(){
       var a,b,c,d,e,f,g,h,i
       a='<a href=\"mai'
       b='person2'
       c='\">'
       a+='lto:'
       b+='@'
       e='</a>'
       f=''
       b+='email.com'
       g='<img src=\"'
       h=''
       i='\" alt="Email us." border="0">'

       if (f) d=f
       else if (h) d=g+h+i
       else d=b

       document.write(a+b+c+d+e)
       }
       escramble()
       //-->

       </script></em>

   </div>

   <div class="spacer">&nbsp;</div>
  • 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-06-15T15:37:55+00:00Added an answer on June 15, 2026 at 3:37 pm

    Quick and dirty approach that works for your sample data:

    >>> res = re.findall(r"b\+?='(.*?)'", html)
    >>> res
    ['person1', '@', 'email.com', 'person2', '@', 'email.com']
    >>> emails [''.join(group) for group in zip(*[iter(res)]*3)]
    ['person1@email.com', 'person2@email.com']
    

    And since this is already horrible then let’s really kludge it:

    >>> names = [name.split('>', 1)[1] for name in re.findall(r'href="people(.*?)</a>', html)]
    >>> names
    ['person1', 'person2']
    >>> zip(names, emails)
    [('person1', 'person1@email.com'), ('person2', 'person2@email.com')]
    

    Note – this just works on your sample data – HTML is fickle – so don’t expect this to be robust – easily managable etc… etc…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.