使用python从网页解析数据

时间:2017-05-11 00:45:34

标签: python python-2.7

有人可以帮我解析一下网页上的特定数据吗?这是网页上的内容。

HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(true), req); InterfaceHttpData data = decoder.next();

我只需要整个内容中的id。请注意我们在网页内容中有两次id,所以我需要网页上的所有ID。这是我为转储Web内容而编写的代码,但无法解析我需要的数据。请帮帮我。

{"sites":[{"id":"XX","name":"YY","url":"ZZ","username":"AA","password":"BB","siteId":"0"},{"id":"XX","name":"YY","url":"ZZ","username":"AA","password":"BB","siteId":"0"}]}

1 个答案:

答案 0 :(得分:0)

您的内容是一个json文档,您可以使用json library对其进行解析并将其用作python对象:

def doMyStuff(self):
    <get a self.file_list>
    self.num_completed = 0
    self.threads = []
    self.workers = []
    for f in self.file_list:
        w = Worker(f)
        w.done.connect(self.update_this)
        thread = QThread()
        w.moveToThread(thread)
        thread.started.connect(w.process)
        thread.finished.connect(self.thread_complete)
        self.threads.append(thread)
        self.workers.append(worker)