【发布时间】:2019-10-24 10:41:24
【问题描述】:
我已成功将 JS 中列出的网站抓取到本地 .html 文件中,但输出不足。
问题是:
- 它只产生最后一个查询(audioSource),而不产生其他请求
- 它只找到第 1 集,然后停在那里。如何让它重复直到找到结尾?
非常感谢
import requests
import json
from bs4 import BeautifulSoup
JSONDATA = requests.request("GET", "https://thisiscriminal.com/wp-json/criminal/v1/episodes?posts=1000000&page=1")
JSONDATA = JSONDATA.json()
for line in JSONDATA['posts']:
soup = BeautifulSoup(line['episodeNumber'],'lxml')
soup = BeautifulSoup(line['title'],'lxml')
soup = BeautifulSoup(line['image']['large'],'lxml')
soup = BeautifulSoup(line['excerpt']['long'],'lxml')
soup = BeautifulSoup(line['audioSource'],'lxml')
with open("output1.html", "w") as file:
file.write(str(soup))
【问题讨论】:
标签: python html json python-3.x beautifulsoup