为什么 urllib.urlopen.read() 与源代码不对应? [英] Why urllib.urlopen.read() does not correspond to source code?

查看:34
本文介绍了为什么 urllib.urlopen.read() 与源代码不对应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取以下网页:

I'm trying to fetch the following webpage:

import urllib
urllib.urlopen("http://www.gallimard-jeunesse.fr/searchjeunesse/advanced/(order)/author?catalog[0]=1&SearchAction=1").read()

结果与我使用谷歌浏览器检查网页源代码时看到的不符.

The result does not correspond to what I see when inspecting the source code of the webpage using Google Chrome for example.

你能告诉我为什么会发生这种情况以及我如何改进我的代码来克服这个问题吗?

Could you tell me why this happens and how I could improve my code to overcome the problem?

感谢您的帮助.

推荐答案

你从 urlopen 得到的是原始网页,这意味着没有执行 javascript 没有使用 css;您从 Chrome(或其他浏览器)获得的是最终网页,其中包含可执行的 javascript(可能会改变 HTML)、css 渲染等.所有这些都不会在 urlopen 中发生...

What you are getting from urlopen is the raw webpage meaning no javascript is executed css is not used; where as what you get from Chrome (or other browsers) is final webpage which included executable javascript (which might alter the HTML), css rendering etc. all of which does not happen in urlopen...

因此不同,希望这很清楚

Hence the difference, hope this is clear

这篇关于为什么 urllib.urlopen.read() 与源代码不对应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆