【问题标题】:How to read data from a json file when it loads after a time delay, in pythonpython - 在延迟时间后加载时如何从json文件中读取数据
【发布时间】:2020-07-05 06:05:35
【问题描述】:

http://mediafile.cloud/e1b227799b1e3e3b

我正在尝试在python中使用urllib读取此页面,但它在60秒的时间延迟之前读取数据,我如何在时间延迟之后获取数据

from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import time

domain=Request("http://mediafile.cloud/e1b227799b1e3e3b")
domain.add_header('User-Agent', 'Mozilla/5.0')
response =urlopen(domain)
time.sleep(60)
html = response.read()

【问题讨论】:

  • 使用 urllib 可能是可行的,但我想说当你想与网页进行交互时使用 selenium 会更合适。
  • 您可能需要一个 python 模块来呈现 JavaScript 脚本 - 可能是 requests_htmlselenium

标签: python python-3.x web-scraping beautifulsoup urllib


【解决方案1】:

您的代码是正确的,您只需进行一项更改: 你提到了这里的大写T Time.sleep(60)small t import time 在这里 由于它区分大小写,因此您的代码将不起作用。让它变小,它会正常工作。

【讨论】:

  • 抱歉问题中的拼写错误,我确实使用了 small t 并且确实得到了没有错误的输出,但问题仍然存在
猜你喜欢
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
  • 2019-12-20
  • 1970-01-01
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多