python - 我的 URL 数据不会填写我的 SQL 数据表 Python
问题描述
import json
import urllib
import sqlite3
def loading():
url = 'https://jobs.github.com/positions.json?page=1' # URL for API 1-5json_obj = urllib.urlopen(url)
response = urllib.urlopen(url)
data = json.load(response) # loads the url and set it into data variable
for item in data[0].keys():
return data # Get the keys
# def loading():
# print " LOADING API(s)"
# urllib.urlopen('https://jobs.github.com/positions.json?page=1')
# temp = json.dumps(data[1])
# print (json.dumps(data[1]))
# print (" ")
def createDB(data):
conn = sqlite3.connect('comp.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE IF NOT EXISTS comp
(id text primary key, type text, url text,created_at timestamp, company text, company_url text, location text, title text, description text, how_to_apply text, company_logo text
)''')
temp_values = list(tuple())
for item in data:
list_of_values = [v for k, v in item.items()]
tuple_of_values = tuple(list_of_values)
temp_values.append(tuple_of_values)
#TO DO
# Make sub sets for each category call
# put in category for each ? in table
c.executemany('INSERT INTO comp VALUES (?,?,?,?,?,?,?,?,?,?,?)', temp_values)
conn.commit()
def main():
data = loading()
createDB(data)
main()
我收到这个编译错误
Traceback (most recent call last):
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 43, in <module>
main()
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 40, in main
data = loading()
File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 9, in loading
data = json.load(response) # loads the url and set it into data variable
AttributeError: 'module' object has no attribute 'load'
解决方案
推荐阅读
- javascript - 将方法的参数声明为接口类型,并将不相关的对象传递给它
- sql - 如何使用 regexp_substr 提取包名
- javascript - 例如,如果有人试图复制粘贴文本,我如何只允许数字输入做出反应
- python - 使用 Django Channels 向多个组发送消息
- java - 我无法解决错误:找不到资源 drawable/abc (aka com.example.myapplication:drawable/abc)
- django-rest-framework - 如何从 GET 请求中获取 JSON 数据(正文应用程序/json)?
- performance - 先进先出库存(FIFO)公式计算很慢
- javascript - 为什么浏览器同步与 gulp 不起作用
- android - 无法使用 onSaveInstanceState 保存片段状态
- python - 如果扩展是单线程的,是否需要 Python GIL