Python Forum
Need alittle hlpl with an image scraper.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need alittle hlpl with an image scraper.
#1
Hello one and all,
I am back with , I hope is a small problem. I found this image scraper that looks just what I been looking for. I been working on this one error for over a week now. I google it and I can't find anything that is close to what I have here.
Here is the code, I am using python 2.7.12 on wim 7:



import requests
import mechanize
from lxml import html
import sys
import urlparse
import time

def grab_my_pictures():
    respones = requests.get(final_link)
    parsed_body = html.fromstring(response.text)
    images = parsed_body.xpath('//img/@src')
    if not images:
        sys.exit("Found no images")
    images = [urlparse.urljoin(response.url, url)for url in images]
    print 'Found %s images' % len(images)

    for url in images[1:50]:
        r = requests.get(url)
        r = open('pics2/%s' % url.split('/')[-1], 'w')
        f.write(r.content)
        f.close()

website_name = raw_input("Please enter the name of the website ")
list_of_links = []
br = mechanize.browser()
br.set_handle_robot(False)
final_website = "http//" + website_name
print final_website
respons = br.open("http//" + website_name)  
Their still some code that I do not know what it does, I been taking it line by line learning what each line does.
The error is this:


Traceback (most recent call last):
  File "C:/Users/renny and kite/Desktop/play_with_image/test_1.py", line 25, in <module>
    br = mechanize.browser()
AttributeError: 'module' object has no attribute 'browser'



I just don't know what attribute I should put in this function br = mechanize.browser()

I been to a few sites, but can't find anything about mechanize.browser()
site one http://wwwsearch.sourceforge.net/mechanize/doc.html
site two  http://stockrt.github.io/p/emulating-a-b...mechanize/
site three http://www.pythonforbeginners.com/mechan...mechanize/, now I found this code[br = mechanize.browser()] on this site, but I could not get it to work.

So no luck so far, that is why I am here again. Hope someone can help, I would like to get this peace of code to work.
Thank you
Reply


Messages In This Thread
Need alittle hlpl with an image scraper. - by Blue Dog - Dec-21-2016, 07:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Web scraper tomenzo123 8 4,733 Aug-18-2023, 12:45 PM
Last Post: Gaurav_Kumar
  Web scraper not populating .txt with scraped data BlackHeart 5 1,698 Apr-03-2023, 05:12 PM
Last Post: snippsat
  Image Scraper (beautifulsoup), stopped working, need to help see why woodmister 9 4,306 Jan-12-2021, 04:10 PM
Last Post: woodmister
  Court Opinion Scraper in Python w/ BS4 (Currently exports to CSV) need help with SQL MidnightDreamer 4 3,146 Mar-12-2020, 09:57 AM
Last Post: BrandonKastning
  Python using BS scraper paulfearn100 1 2,645 Feb-07-2020, 10:22 PM
Last Post: snippsat
  web scraper using pathlib Larz60+ 1 3,288 Oct-16-2017, 05:27 PM
Last Post: Larz60+
  Made a very simple email grabber(scraper) Blue Dog 4 7,089 Dec-13-2016, 06:25 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020