我正在尝试通过"httplib.HTTPSConnection"连接到这个网站"android-review.googlesource.com",这实际上是Gerrit(用于审查代码的工具),Gerrit API提供了JSON格式的审阅数据的接口.我需要收集JSON数据.您可以在此处找到有关Gerrit的更多信息:https://gerritreview.googlesource.com/Documentation/rest-api.html
让我解释一下源代码.有一个名为"GetRequestOrCached"的函数将数据保存在文件中以供缓存使用,另一个函数"MakeRequest"创建与网站的连接并返回响应.但是错误与json.dumps用于请求(req)的部分有关,该请求是字典.
这是错误:
TypeError: <built-in function id> is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
这是代码:
import socket, sys
import httplib
import pyodbc
import json
import types
import datetime
import urllib2
import os
import logging
import re, time
def GetRequestOrCached( url, method, data, filename):
path = os.path.join("json", filename)
if not os.path.exists(path):
data = MakeRequest(url, method, data)
time.sleep(1)
data = data.replace(")]}'", "")
f = open(path, "w")
f.write(data)
f.close()
return open(path).read()
def MakeRequest(url, method, data, port=443):
successful = False
while not successful: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用HtmlAgilityPack来解析网页信息.这是我的代码:
using System;
using HtmlAgilityPack;
namespace htmparsing
{
class MainClass
{
public static void Main (string[] args)
{
string url = "https://bugs.eclipse.org";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
foreach(HtmlNode node in doc){
//do something here with "node"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图访问时,doc.DocumentElement.SelectNodes我无法DocumentElement在列表中看到.我在引用中添加了HtmlAgilityPack.dll,但我不知道是什么问题.