Python的Glassdoor API [英] Python Glassdoor API

查看:552
本文介绍了Python的Glassdoor API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Python从他们的API glassdoor数据:

I'm trying to get glassdoor data from their API in Python:

import urllib2

id1 = 'x'
key = 'y'
action = 'employers'
company = 'company'

basepath = 'http://api.glassdoor.com/api/api.htm?v=1&format=json&t.p='
url = basepath + id1 + '&t.k=' + key + '&action=' + action + '&q=' + company + '&userip=192.168.43.42&useragent=Mozilla/5.0'

response = urllib2.urlopen(url)
html = response.read()

和我得到了以下错误:

>>> response = urllib2.urlopen(url)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "//anaconda/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "//anaconda/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "//anaconda/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "//anaconda/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "//anaconda/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden

任何人都可以帮助...?

Can anyone help...?

感谢

推荐答案

下面是工作code。与一些改进,加入BeautifulSoup模块,并设置用户代理的 HDR 变量。

below is the working code with some improvement by adding BeautifulSoup module and set User-Agent in hdr variable.

import urllib2, sys
from BeautifulSoup import BeautifulSoup

url = "http://api.glassdoor.com/api/api.htm?t.p=yourID&t.k=yourkey&userip=8.28.178.133&useragent=Mozilla&format=json&v=1&action=employers&q="
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(url,headers=hdr)
response = urllib2.urlopen(req)
soup = BeautifulSoup(response)

希望它能帮助,谢谢

Hope it help, thanks

这篇关于Python的Glassdoor API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆