Beautifulsoup "list Object Has No Attribute" Error
I'm trying to scrape temperatures from a weather site using the following: import urllib2 from BeautifulSoup import BeautifulSoup f = open('airport_temp.tsv', 'w') f.write('L
Solution 1:
The .findAll()
method returns a list of matches. If you wanted one result, use the .find()
method instead. Alternatively, pick out a specific element like the rest of the code does, or loop over the results:
location = soup.find('h1').text
or
locations = [el.text for el in soup.findAll('h1')]
or
location = soup.findAll('h1')[2].text
Solution 2:
This is quite simple. findAll
returns list, so if you are sure that there is only one interesting you element then: soup.findAll('H1')[0].text
should work
Post a Comment for "Beautifulsoup "list Object Has No Attribute" Error"