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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:41:04+00:00 2026-05-14T15:41:04+00:00

To practise some more bits of python I’ve been having a go at the

  • 0

To practise some more bits of python I’ve been having a go at the challenges on pythonchallenge.com

In brief, this challenge as a first step requires one to load an html page from a url with a number at the end. The page contains a single line of text which has in it a number. That number is used to replace the existing one in the url, and so take you to the next page in the sequence. Apparently this continues for some time… (there is more to this challenge, but getting that part working is the first step).

My code for doing so is below (limited to running through what should be the first four pages in the sequence, for the time being). For some reason it works the first time – it gets the second page in the sequence, reads the number, goes to the third, and reads the number there. But then it gets stuck on the third. I don’t understand why, though think it might be something to do with my attempt to turn the number into a string before putting it on the end of the URL. To answer the obvious question, yes I know that pythonchallenge is working OK – you can do the url-numbers thing manually for as long as you have the patience, to confirm, if you like :p

import httplib2
import re

counter = 0
new = '12345' #the number for the initial page in the sequence, as a string

while True:
    counter = counter + 1
    if counter == 5:
        break

    original = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
    nextpage = original+new     #each page in the sequence is visited by adding 
                                #the number after 'nothing='
    print(nextpage)

    h = httplib2.Http('.cache')
    response, content = h.request(nextpage, "GET")  #get the content of the page, 
                                                    #which includes the number for the 
                                                    #*next* page in the sequence

    p = re.compile(r'\d{4,5}$')     #regex to find a 4 to 5 digit number at the end of
                                    #the content

    new = str((p.findall(content)))     #make the regex result a string - is this
                                            #where the problem lies?

    print('cached?', response.fromcache)    #I was worried my requests were somehow
                                            #being cached not actually sent afresh to
                                            #pythonchallenge. But it seems they aren't.

    print(content)
    print(new)

And the output of the above is as follows, below. It seems to work fine for the first run through (adding the 92512 to the url and successfully getting the next page and finding the next value) but after that it just gets stuck, and doesn’t seem to load the following page in the sequence. Testing by changing the url manually in a browser confirms that the number is correct and pythonchallenge is working OK.

It looks to me like something is going wrong turning my regex search into a string to add onto the end of the URL – but why it should work the first time and not the second I don’t know. I was also concerned maybe my requests were only getting as far as a cache (I’m new to httplib2 and not confident about how it does caching) but they seem not to be. I also added a no-cache argument to the request just to be sure (not shown in this code) but it didn’t help.

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

(‘cached?’, False)

and the next nothing is 92512

[‘92512’]

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%5B‘92512’]

(‘cached?’, False)

and the next nothing is 72758

[‘72758’]

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%5B‘72758’]

(‘cached?’, False)

and the next nothing is 72758

[‘72758’]

http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%5B‘72758’]

(‘cached?’, False)

and the next nothing is 72758

[‘72758’]

I would be grateful to anyone who can point out where I am going wrong, as well as for any relevant tips

Thanks in advance…

  • 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-14T15:41:04+00:00Added an answer on May 14, 2026 at 3:41 pm
    http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=['72758']
                                                                 ^^     ^^
    

    The problem is here I think. findall() return a list:

    re.findall(pattern, string[, flags])

    Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.

    — Python doc

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should use the view.yml config file and the include_stylesheets()… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer DELIMITER $$ DROP PROCEDURE IF EXISTS `sample`.`InsGen` $$ CREATE DEFINER=`root`@`localhost`… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer One stored procedure so far as possible: INSERT INTO MyTable(field1,field2)… May 14, 2026 at 10:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.