如何在Python请求中绕过加载屏幕?

huangapple go评论85阅读模式
英文:

How to bypass loading screen in python requests?

问题

I can help you with the translation. Here is the translated content:

所以我有一个网站,名为example.com,我试图发送请求,当您在浏览器上加载该网站时,会有一个加载屏幕,可能持续2-4秒(它不是验证码,也不是Cloudflare),然后转到主页。在Python中,我试图发送HTTP GET请求到该页面,但遇到了加载屏幕,有没有办法完全避免这个屏幕?或者至少等待屏幕消失,然后获取响应?

import requests

response = requests.get("example.com")
print(response.text)

期望的响应应该是主页,而不是加载屏幕。我想避免使用Selenium、Playwright或任何浏览器仿真包,只有作为最后的手段,如果没有可能的方法可以仅使用requests库来绕过它。

英文:

So I have a website, named example.com I am trying to send a requests too, when you load up the site on the browser there is a loading screen for maybe, 2 - 4 seconds (it is not captcha nor cloudflare) and then goes to the main page. In python I am trying to send a http get requests to that page but am met with the loading screen, is there anyway I can compelstely avoid that screen? Or atleast wait for the screen to pass then retrieve the response?

import requests 

response = requests.get(“example.com”)
print(response.text)

The desired response would be the main page, not the loading screen. I would like to refrain from using selenium, playwright or any browser emulation package, only as a last resort if there is NO possible way to bypass this simply with requests library.

答案1

得分: 1

这应该可以运行。

import pyppeteer
import asyncio
pageurl = ""
async def main():
    # 启动 Chromium 浏览器,也可以使用 Chrome 代替 Chromium。
    browser = await pyppeteer.launch(headless=False)
    # 创建一个空白页面
    page = await browser.newPage()
    # 转到请求的页面并在网站上运行动态代码。
    await page.goto(pageurl)
    # 提供页面的 HTML 内容
    cont = await page.content()
    return cont

# 打印用户配置文件的 HTML 代码:tupac
print(asyncio.get_event_loop().run_until_complete(main()))
英文:

this should work.

import pyppeteer
import asyncio
pageurl = ""
async def main():
    # launches a chromium browser, can use chrome instead of chromium as well.
    browser = await pyppeteer.launch(headless=False)
    # creates a blank page
    page = await browser.newPage()
    # follows to the requested page and runs the dynamic code on the site.
    await page.goto(pageurl)
    # provides the html content of the page
    cont = await page.content()
    return cont

# prints the html code of the user profiel: tupac
print(asyncio.get_event_loop().run_until_complete(main()))

huangapple
  • 本文由 发表于 2023年4月10日 19:35:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976733.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定