1

我不确定它是否是我的计算机的设置(Windows 7,Python3.8,刚刚安装了 requests_html),但无论我选择哪个站点,该render方法都导致timeout error 我玩弄了 timeout 参数,但没有运气.

import os
import sys
import requests_html
import requests
import pyppeteer



def get_request(url, render = False):

    session = requests_html.HTMLSession()
    res = session.get(url)

    try:
        res.raise_for_status()
    except ValueError as e:
        raise('Dead link')

    if render:
        res.html.render(sleep = 2, timeout = 20)

    return res, session


def test_render():
    url = 'https://www.yahoo.com/'
    res, session = get_request(url, render = True)
4

1 回答 1

0

我已经尝试过了,它非常有效:

import os
import sys
import requests_html
import requests
import pyppeteer



def get_request(url, render = False):

    session = requests_html.HTMLSession()
    res = session.get(url)

    try:
        res.raise_for_status()
    except ValueError as e:
        raise('Dead link')

    if render:
        res.html.render(sleep = 2, timeout = 20)

    return res, session


def test_render():
    url = 'https://www.yahoo.com/'
    res, session = get_request(url, render = True)

#test_render()
[res, session]= get_request('https://www.yahoo.com/', render=True)
print(res.text)

检查您的设置,因为我没有更改刚刚调试的任何内容

于 2020-09-18T19:24:21.497 回答