12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import suggests
- import networkx as nx
- import pyvis
- import time
- from pyvis.network import Network
- import pickle
- kw='裝修'
- s = suggests.suggests.get_suggests(kw, source='google')
- G = nx.Graph()
- for sg in s['suggests']:
- G.add_edge(kw,sg,weight=1)
- print(sg)
- time.sleep(1)
- s2 = suggests.suggests.get_suggests(sg, source='google')
- for elmt in s2['suggests']:
- G.add_edge(sg,elmt,weight=1)
- G.remove_edges_from( list(nx.selfloop_edges(G)))
- pickle.dump( G, open( "gs2.p", "wb" ) )
- pyG = Network(height="750px", width="100%",bgcolor="#333333",font_color="white")
- pyG.from_nx(G)
- pyG.show('gs.html')
|