[英]use requests get page but not source code in python, why? how can i get source code?
页面网址是www.nenu.edu.cn/intramural/content/news/110.php
使用chrome获取源代码与使用请求不一样。 我使用requests.get是
u'\r\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n<html xmlns="http://www.w3.org/1999/xhtml">\r\n<head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />\r\n<title>\u4e1c\u5317\u5e08\u8303\u5927\u5b66</title>\r\n<link href="../../images/nenu_news.css" rel="stylesheet" type="text/css" />\r\n</head>\r\n<body>\r\n\r\n<script language="javascript" type="text/javascript"> window.location ="http://www.nenu.edu.cn/intramural/content/news/110.php";</script>'
如果您查看requests.get
给您的HTML,您将看到以下代码段:
<script language="javascript" type="text/javascript">
window.location ="http://www.nenu.edu.cn/intramural/content/news/110.php";
</script>
这意味着当Chrome加载页面时,页面中的小Javascript代码段会告诉浏览器导航到http://www.nenu.edu.cn/intramural/content/news/110.php
-it is可能是您在Chrome中查看来源时所看到的该页面的HTML内容。 但是, requests
不会在响应中解析和执行Javascript,因为它不是浏览器,因此它只是为您提供文字响应文本。
就那么简单。
编辑:实际上你的问题(特别是标题)是如此糟糕(在一般的清晰度和你非常差的英语语法方面),我不确定这是你唯一要求的,所以请尝试在将来更加努力地写下你的问题。
PS。 使用window.location = ...
或类似技巧进行重定向的页面很难在不使用完整浏览器或浏览器模拟器的情况下进行爬网。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.