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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:11:21+00:00 2026-06-12T14:11:21+00:00

I am trying to scrap a website using lxml and mechanize, and I got

  • 0

I am trying to scrap a website using lxml and mechanize, and I got an error:

AttributeError: ‘NoneType’ object has no attribute ‘xpath’

After some check I found html returned None.

The funny part is, this code works on other websites, only failed to work this particular website (http://www.selangortimes.com)

url = 'http://www.selangortimes.com'
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_refresh(False)
br.addheaders = [('User-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)')]
br.open(url)
resp = br.response()
html = lxml.html.parse(resp).getroot()
link_targets = [link.attrib.get('href') for link in html.xpath(expr)]

Appreciate your help 🙂

Update:
An example of a working website using the above code – http://www.themalaysianinsider.com

  • 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-12T14:11:23+00:00Added an answer on June 12, 2026 at 2:11 pm

    The following slightly revised version of the code you have posted, using lxml 2.3.6 and mechanize 0.2.5 produces a list of all the href attributes in <a> elements at the http://www.selangortimes.com url. Note concerning your latest comment that you have to import lxml.html.

    import mechanize
    import lxml.html
    
    url = 'http://www.selangortimes.com'
    br = mechanize.Browser()
    br.set_handle_robots(False)
    br.set_handle_refresh(False)
    br.addheaders = [('User-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)')]
    br.open(url)
    resp = br.response()
    html = lxml.html.parse(resp).getroot()
    link_targets = [link.attrib.get('href') for link in html.xpath('//a')]
    print(link_targets)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to scrape images and data from a website using Xpath but keeps showing
I'm currently trying to scrape a website that has fairly poorly-formatted HTML (often missing
I'm trying to scrap a website that requires to submit two forms : a
I am trying to scrap some content from a website but the code below
I'm trying to scrape the price field from this website using the HTML Agility
I'm trying to scrape some data off of the FEC.gov website using python for
I'm trying to retrieve images from any site that has images I'm using simplehtmldom
I'm trying to scrape a remote website. I'm using PHP Curl, and my code
I'm trying do scrape this website with python and lxml. Its working greate on
I am trying to scrape a table website with mechanize. I want to scrape

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.