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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:38:00+00:00 2026-06-14T04:38:00+00:00

from twill.commands import * from bs4 import BeautifulSoup from urllib import urlopen import urllib2

  • 0
from twill.commands import *
from bs4 import BeautifulSoup
from urllib import urlopen
import urllib2

with open('urls.txt') as inf:
    urls = (line.strip() for line in inf)
    for url in urls:
        try:
            urllib2.urlopen(url)
        except urllib2.HTTPError, e:
            print e
        site = urlopen(url)   
        soup = BeautifulSoup(site)
        for td in soup.find_all('td', {'class': 'subjectCell'}):
            print td.find('a').text

my code opens only a single page from each url of the file, sometimes there are more pages, in that case the pattern for the next pages would be &page=x

here are those pages i’m talking about:

http://www.last.fm/user/TheBladeRunner_/library/tags?tag=long+track
http://www.last.fm/user/TheBladeRunner_/library/tags?tag=long+track&page=7

  • 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-14T04:38:01+00:00Added an answer on June 14, 2026 at 4:38 am

    You could read the href attribute from the next_page link and add it to your urls list (yes, you should change your tuple to a list). It could be something like this:

    from twill.commands import *
    from bs4 import BeautifulSoup
    from urllib import urlopen
    import urllib2
    import urlparse
    
    with open('urls.txt') as inf:
        urls = [line.strip() for line in inf]
        for url in urls:
            try:
                urllib2.urlopen(url)
            except urllib2.HTTPError, e:
                print e
            site = urlopen(url)   
            soup = BeautifulSoup(site)
            for td in soup.find_all('td', {'class': 'subjectCell'}):
                print td.find('a').text
    
            next_page = soup.find_all('a', {'class': 'nextlink'}):
            if next_page:
                next_page = next_page[0]
                urls.append(urlparse.urljoin(url, next_page['href']))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple twill code >>> from twill.commands import * >>> go(http://stackoverflow.com:80) ==>
How can i set it to print chinese and accented characters? from twill.commands import
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
I am doing an import of data from excel spreadsheet to SQLServer 2005 via
I want to return a set of values from function till the point they
How do I read from a file till a particular character is reached and
date(Y,1340896077)//1340896077 are the seconds till 2012 from 1970 gives 2012 which is normal And
I use SplFileObject and LimitIterator to read content from position x till y of
From my website, I have a button which calls a method and then generates
From the Scala API , I got the following example, which does not compile;

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.