python - Get the content HTML of an API -
i'm tring content of api result in python.
html template image inside.
i tried lot of method content don't work everytime.
the fuction :
def screenshotlayer(self, access_key, secret_keyword, domain, args): domain = "http://" + domain url = "http://api.screenshotlayer.com/api/capture?access_key=api_key&url=http://google.com&viewport=1440x900&width=250" html = urllib2.urlopen(url).read() print html soup = beautifulsoup(html, 'html.parser') return soup.findall('img')[0]['src']
when print html
, there lot of incomprehensible characters.
can me resove problem ?
thank much.
the api not returns html, raw image file (default png).
you need see if status_code
200, , if so, save result file.
import requests res = requests.get( 'http://api.screenshotlayer.com/api/capture', params={ 'access_key': 'api_key', 'url': 'http://google.com&viewport=1440x900&width=250' } ) if(res.status_code == 200) open('output.png', 'w+b') f: f.write(res.content.encode('utf8')) else: print('api returns error: %s' % res.content)
Comments
Post a Comment