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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:40:43+00:00 2026-06-14T12:40:43+00:00

I am noob with python, been on and off teaching myself since this summer.

  • 0

I am noob with python, been on and off teaching myself since this summer. I am going through the scrapy tutorial, and occasionally reading more about html/xml to help me understand scrapy. My project to myself is to imitate the scrapy tutorial in order to scrape http://www.gamefaqs.com/boards/916373-pc. I want to get a list of the thread title along with the thread url, should be simple!

My problem lies in not understanding xpath, and also html i guess. When viewing the source code for the gamefaqs site, I am not sure what to look for in order to pull the link and title. I want to say just look at the anchor tag and grab the text, but i am confused on how.

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from tutorial.items import DmozItem

class DmozSpider(BaseSpider):
name = "dmoz"
allowed_domains = ["http://www.gamefaqs.com"]
start_urls = ["http://www.gamefaqs.com/boards/916373-pc"]


def parse(self, response):
    hxs = HtmlXPathSelector(response)
    sites = hxs.select('//a')
    items = []
    for site in sites:
        item = DmozItem()
        item['link'] = site.select('a/@href').extract()
        item['desc'] = site.select('text()').extract()
        items.append(item)
    return items

I want to change this to work on gamefaqs, so what would i put in this path?
I imagine the program returning results something like this
thread name
thread url
I know the code is not really right but can someone help me rewrite this to obtain the results, it would help me understand the scraping process better.

  • 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-14T12:40:44+00:00Added an answer on June 14, 2026 at 12:40 pm

    The layout and organization of a web page can change and deep tag based paths can be difficult to deal with. I prefer to pattern match the text of the links. Even if the link format changes, matching the new pattern is simple.

    For gamefaqs the article links look like:

    http://www.gamefaqs.com/boards/916373-pc/37644384

    That’s the protocol, domain name, literal ‘boards’ path. ‘916373-pc’ identifies the forum area and ‘37644384’ is the article ID.

    We can match links for a specific forum area using using a regular expression:

    reLink = re.compile(r'.*\/boards\/916373-pc\/\d+$')
    if reLink.match(link)
    

    Or any forum area using using:

    reLink = re.compile(r'.*\/boards\/\d+-[^/]+\/\d+$')
    if reLink.match(link)
    

    Adding link matching to your code we get:

    import re
    reLink = re.compile(r'.*\/boards\/\d+-[^/]+\/\d+$')
    
    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        sites = hxs.select('//a')
        items = []
        for site in sites:
            link = site.select('a/@href').extract()
            if reLink.match(link)
                item = DmozItem()
                item['link'] = link
                item['desc'] = site.select('text()').extract()
                items.append(item)
        return items
    

    Many sites have separate summary and detail pages or description and file links where the paths match a template with an article ID. If needed, you can parse the forum area and article ID like this:

    reLink = re.compile(r'.*\/boards\/(?P<area>\d+-[^/]+)\/(?P<id>\d+)$')
    m = reLink.match(link)
    if m:
        areaStr = m.groupdict()['area']
        idStr = m.groupdict()['id']
    

    isStr will be a string which is fine for filling in a URL template, but if you need to calculate the previous ID, etc., then convert it to a number:

    idInt = int(idStr)
    

    I hope this helps.

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

Sidebar

Related Questions

Python noob so I might be going about this the wrong way I want
Apologies for the noob Python question but I've been stuck on this for far
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
Python noob trying to learn Pylons. I'm using the QuickWiki tutorial ( http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/ )
Python noob; please explain why this loop doesn't exit. for i in range(0,10): print
I am a noob to Python and have not had any luck figuring this
I keep getting an error whenever I enter this code (I'm a python noob
This is the what-I-want ( warning: Python noob here, this might be an incorrect
Python/Unix noob. On Mac OSX. Been running Python 2.7.2 for a few weeks, along
this may sound like a strange question from a Python noob, but here's the

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.