vendredi 26 mai 2017

I am Coding this Web scraper in Python. Getting an Error- 'ResultSet' object has no attribute 'find_all'

I got this error while coding a webscraper. I am looking to scrap an A href tag in a h4 tag.

The Source code is below

import urllib2
from bs4 import BeautifulSoup
import re
import os


def file_there():
    print 'Source Code Already Saved'
    f = open('J.html','r')

    s = f.read() #Raw Source Code
    source = BeautifulSoup(s,'html.parser') #BeautifulSoup Source Code

    h4  = source.find_all('h4',{'class':'store-name'})

    a = h4.find_all('a')


    for links in a:
        print links.get('href')

if os.path.isfile('J.html'):
    file_there()
else:
    opener = urllib2.build_opener()
    opener.addheaders = [('User-Agent','Chrome')]

    url = 'http://ift.tt/2qlFTlZ'

    site = opener.open(url)

    code = site.read()


    global k
    k = open('J.html','w')
    k.write(code)
    k.close()
    file_there()

What more or less should I add to eradicate the error - 'ResultSet' object has no attribute 'find_all'. Any Help would be appreciatable

Regards, Rajan




Aucun commentaire:

Enregistrer un commentaire