I have a set of websites and their links in this format:
{
"thisite.com" : ["test.com", "example.com"],
"test.com": ["examples.com"]
...
}
How could I turn this into a directed graph easily? I know there are many different libraries, such as NetworkX, but I don't know a way to do this efficiently. I would be turning this graph into an adjacency matrix, so if possible, the library should have a way to do this,
My only solution is this:
def loadgraph(fname):
G=pg.AGraph(directed=True)
for line in open(fname):
j=json.loads(line)
url=j["url"]
G.add_node(url)
for linked_url in j["linkedurls"]:
G.add_edge(url,linked_url)
return G
This is not efficient at the scale I would be trying to run this program at. Does anyone know a more efficient way to do this, or would this be the best solution?