Jupyter requests.get返回不完整的html

时间:2018-08-22 13:33:37

标签: python python-requests jupyter-notebook jupyter

我在Jupyter笔记本中运行以下python代码,但返回的HTML不完整。

import requests 
if __name__ == '__main__':
    target = 'http://www.biqukan.com/1_1094/5403177.html'
    req = requests.get(url=target)
    print(req.text)

然后我以VS代码运行它,返回的是完整的html

我想知道原因,以及如何在Jupyter中返回完整的html。

谢谢。

1 个答案:

答案 0 :(得分:1)

import requests 
target = 'http://www.biqukan.com/1_1094/5403177.html'
req = requests.get(url=target)
req.text

Try it in jupyter. Why is it? Because the mechanism in jupyter.

The reason is that there is something loaded by js. You can find something in line 53 and line 61. You can debug with Chrome, you can find

function read1(){
document.writeln("<div align=center style=\"margin-bottom:8px;\"><script src=\'http://www.biquge.lu/ads/kan_hf.js\'></script></div>");

}

You can try it by yourself, just like it.

enter image description here

Hope helpful.