User Controls
py fags, why my beautifulsoup throwing an error when trying to get ['src'] of an imge
-
2017-02-01 at 6:12 AM UTC
-
2017-02-01 at 6:13 AM UTCstarts at 5 minutes
-
2017-02-01 at 7:04 AM UTCThat's a really horrific way to present code, why not just copy paste the source and stack trace?
Anyway, I don't think that's how you use find, it's not a variadic method. You probably want .select() instead, at least from looking at the docs. -
2017-02-01 at 3:35 PM UTC
import requests
from bs4 import BeautifulSoup as bs
def scrape():
data = bs(requests.get('http://twitter.com/thefiltration').text, 'html.parser')
name = data.find('h1', 'ProfileHeaderCard-name').text
username = data.find('a', 'ProfileHeaderCard-screennameLink').text
avatar = data.find('img', 'ProfileAvatar-image')['src']
banner = data.find('img','ProfileCanopy-headerBg', 'div')['src']
joindata = data.find('span','ProfileHeaderCard-joinDateText').text
about = data.find('p', 'ProfileHeaderCard-bio u-dir').text
print banner
scrape(); -
2017-02-01 at 4:37 PM UTCWhat does the error message say?
-
2017-02-01 at 7:14 PM UTC
-
2017-02-01 at 7:18 PM UTC
Originally posted by Iam https://gyazo.com/ea420f84a7e4e771875b34164043360b
Ah, this means the image doesn't have an attribute called 'src'. So the code is fine, you're just looking for an attribute that isn't there. Does it object if you just remove `['src']`? -
2017-02-02 at 6:26 AM UTC
Originally posted by Iam
import requests
from bs4 import BeautifulSoup as bs
def scrape():
data = bs(requests.get('http://twitter.com/thefiltration').text, 'html.parser')
name = data.find('h1', 'ProfileHeaderCard-name').text
username = data.find('a', 'ProfileHeaderCard-screennameLink').text
avatar = data.find('img', 'ProfileAvatar-image')['src']
banner = data.find('img','ProfileCanopy-headerBg', 'div')['src']
joindata = data.find('span','ProfileHeaderCard-joinDateText').text
about = data.find('p', 'ProfileHeaderCard-bio u-dir').text
print banner
scrape();
thanks blood.
What happens if you try
banner = data.select('.ProfileCanopy-headerBg img')[0]['src']
? -
2017-02-02 at 6:46 PM UTC
Originally posted by Lanny thanks blood.
What happens if you try
banner = data.select('.ProfileCanopy-headerBg img')[0]['src']
?
worked nigger, thanks :) I guess you have to do it all in one run like you did it rather than 'div', 'identifier', 'etc' -
2017-02-02 at 8:01 PM UTCif this twitter profile scraper does what i think it does, is there any way i can get a copy of this