【发布时间】:2018-05-26 19:13:17
【问题描述】:
我正在尝试编写一个程序来抓取我最喜欢的播客的网址。然后我想从后面的数据创建一个本地网站。
我正在尝试创建一个字典,然后可以将其写入为 json 文件,然后使用 javascript 访问该数据。
我希望字典看起来像:
{"url": "www.test.com", "text" : "Podcast 1... foo bar"}
但是,我在分配值时遇到了麻烦。到目前为止我所拥有的:
def findLinks(url):
filename = url[-16:-4] + ".json"
response = requests.get(url).content
soup = BeautifulSoup(response, parseOnlyThese=SoupStrainer('a'))
for link in soup:
if link.has_key('href'):
links[link.attrMap['href']] = link.getText() #Dictionary
writeToJSON(filename, links)
【问题讨论】:
-
你能和these lines一起做点什么吗?
标签: python json dictionary beautifulsoup