【问题标题】:How to wait after request before loading with soup?在加载汤之前如何等待请求?
【发布时间】:2019-04-07 13:33:59
【问题描述】:

我正在尝试向网站请求该请求有效并且我可以加载它

但我试图从该网站获取的内容并没有从那里的服务器恢复,如下所示:

Loading screen

我该如何解决这个问题?

代码:

import requests
from bs4 import BeautifulSoup

res = requests.get('https://9xbuddy.com/process?url=https://streamango.com/embed/accssmlbkfmmsrcd')
soup = BeautifulSoup(res.text, 'html.parser')

links = [items.get('href') for items in soup.find_all('a', {'class': 'leading-normal sm:leading-none block sm:inline-block bg-blue px-6 sm:px-12 lg:px-6 py-2 text-white no-underline shadow hover:opacity-75'})]
print(links) #[] page sill loading

【问题讨论】:

  • 使用像 selenium 这样的方法来自动化浏览器
  • 能否请您发布您的代码
  • 你需要找到真正包含你想要的数据的请求。然后直接请求。始终使用selenium 作为最后的手段。

标签: python-3.x beautifulsoup python-requests


【解决方案1】:

你发出了一个 GET,并解析了它的结果,就好了。 但你没有要求你想要的最终文件。 你要求一个初始加载器来启动一些 JS webpack 延迟加载。

如果您可以从初始 URL 映射到您关心的最终文档, 为此编写一个函数。 否则,如果您需要javascript解释站点逻辑的帮助 要找到最终 URL,您可能需要使用 Selenium

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-04
    • 2020-05-02
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多