小编Mez*_*ezo的帖子

使用“requests-html”时如何获取带有绝对链接路径的原始 html

requests使用库发出请求时https://stackoverflow.com

page = requests.get(url='https://stackoverflow.com')
print(page.content)
Run Code Online (Sandbox Code Playgroud)

我得到以下信息:

<!DOCTYPE html>
    <html class="html__responsive html__unpinned-leftnav">
    <head>
        <title>Stack Overflow - Where Developers Learn, Share, &amp; Build Careers</title>
        <link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196">
        <link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a">
        <link rel="image_src" href="https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a"> 
..........
Run Code Online (Sandbox Code Playgroud)

这里的这些源代码具有绝对路径,但是当使用requests-htmljs 渲染运行相同的 URL 时

with HTMLSession() as session:
    page = session.get('https://stackoverflow.com')
    page.html.render()
    print(page.content)
Run Code Online (Sandbox Code Playgroud)

我得到以下信息:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>StackOverflow.org</title>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/interface.js"></script>
<script type="text/javascript" src="lib/window.js"></script>
<link href="lib/dock.css" rel="stylesheet" …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-requests python-requests-html

5
推荐指数
1
解决办法
1906
查看次数

将“for 循环”从 Python 转换为 C++

对于这个 Pythonfor循环:

for i in range(n-2,-1,-1):
Run Code Online (Sandbox Code Playgroud)

C++ 中的等效代码语法是什么?

c++ python python-3.x

-4
推荐指数
1
解决办法
431
查看次数