【发布时间】:2018-02-21 09:55:49
【问题描述】:
我已经从论坛中抓取了一些数据(使用 Python),并将其放入字典中,如下所示:
thread = {"1.Init_Post": init_post,
"2.Time_Posted": time_posted,
"3.URL": url,
"4.Discussion_Posts": discussion_posts,
"5.Discussion_Post_Times": post_dates}
它包含初始帖子、初始帖子的发布时间、原始帖子的 URL、相应的讨论帖子以及每个讨论帖子的发布时间。
一个讨论的输出示例是:
{'1.Init_Post': u'I purchased a piece of land over 12 years ago which did not come with any title guarantee. I now wish to register this with the land registry. Does anyone know how I do this please? thanks so much',
'2.Time_Posted': '17/08/17 22:47',
'3.URL': 'http://www.thelawforum.co.uk/how-register-land-unregistered-title',
'4.Discussion_Posts': [u'How did you manage that? Registration has been compulsory for years. https://www.gov.uk/government/publications/first-registrations/practice-...',
u'I read that it had to be done within 3 months and that regime started in 1998? i have another look at the emails from the solicitor when it was purchased in 2005. The solicitor said the land registry had refused to register the land because its previous use of grazing livestock and cutting hay was not sufficiently strong to warrant granting of title. So we purchased indemnity insurance and was told to wait 10/12 years before trying again. was this advice incorrect? thanks',
u'sounds about right. Try with LR again.',
u'Registration has been must for any land you buy from someone. How did you manage this issue from last 12 years. You need to consult a good lawyer. Or need to create documents as soon as possible.'],
'5.Discussion_Post_Times': ['18/08/17 08:19',
'18/08/17 09:42',
'18/08/17 13:25',
'02/09/17 06:14']}
我想要的是一个分层文件(我可以把它变成一个 JSON),它看起来像这样:
{'1.Init_Post': u'I purchased a piece of land over 12 years ago which did not come with any title guarantee. I now wish to register this with the land registry. Does anyone know how I do this please? thanks so much',
'2.Time_Posted': '17/08/17 22:47',
'3.URL': 'http://www.thelawforum.co.uk/how-register-land-unregistered-title',
'4.Discussion':[
{'a.Discussion_Post':u'How did you manage that? Registration has been compulsory for years. https://www.gov.uk/government/publications/first-registrations/practice-...',
'b.Discussion_Post_Time':'18/08/17 08:19'},
{'a.Discussion_Post':u'I read that it had to be done within 3 months and that regime started in 1998? i have another look at the emails from the solicitor when it was purchased in 2005. The solicitor said the land registry had refused to register the land because its previous use of grazing livestock and cutting hay was not sufficiently strong to warrant granting of title. So we purchased indemnity insurance and was told to wait 10/12 years before trying again. was this advice incorrect? thanks',
'b.Discussion_Post_Time':'18/08/17 09:42'},
{'a.Discussion_Post':u'sounds about right. Try with LR again.',
'b.Discussion_Post_Time':'18/08/17 13:25'},
{'a.Discussion_Post':'Registration has been must for any land you buy from someone. How did you manage this issue from last 12 years. You need to consult a good lawyer. Or need to create documents as soon as possible.',
'b.Discussion_Post_Time':'02/09/17 06:14'}
]
}
我看过这个问题:Translate a table to a hierarchical dictionary?。但我认为我可以比把它变成一个表格然后变成一个层次结构更有效。任何关于如何欣赏的建议!
【问题讨论】:
-
您需要付出一些努力。 adding the two lists into a dictionary 并将其嵌入到
Discussion键下的原始字典中怎么样?或在您的情况下将它们附加到该列表...
标签: python json web-scraping