【问题标题】:how to crawl hidden type html in python如何在python中抓取隐藏类型的html
【发布时间】:2019-08-18 15:59:16
【问题描述】:

我正在尝试从网站抓取和获取数据。我想知道数据并将其显示到我的网站。

我无法从我的大学网站抓取数据。

我想知道正文 -> 文档 -> 文档 -> ,,,

但是当我尝试用 BeautifulSoup 爬行时,我不能这样做

我确实需要这些数据,而且我还没有使用任何其他编程语言...

我该如何爬行?

下面是图片,我认为红线会有问题。

import requests
from bs4 import BeautifulSoup

r = requests.get('http://sg.eulji.ac.kr/ejuv')
soup = BeautifulSoup(r.content, 'html')

print(soup)

HTML

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<title>::-===-=-=-=-=-=-=-=-::</title>
<link href="/html/css/redmond_ori/jquery-ui-1.9.2.custom.min.css" media="screen" rel="stylesheet" type="text/css"/>
<script src="/html/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="/html/js/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
<!-- netFunnel연결 js파일 -->
<!-- <SCRIPT type=text/javascript src="/html/js/netfunnel/netfunnel.js" charset=utf-8></SCRIPT> -->
<script charset="euc-kr" src="/html/js/netfunnel/netfunnel.js" type="text/javascript"></script>
<style>
  body {
    margin : 0px;
    padding : 0px;
  }
  .ui-widget{font-size:0.9em}
</style>
<script>
function msgAlert(msg){
    $("#msg").html(msg.replace(/\r|\n/gi,"<br>"));
    $("#message").dialog({
        resizable: false,
        width: 400,
        modal: true,
        closeOnEscape: false,
        resizable: false,
        draggable: true,
        buttons: {
            " close ": function() {
                $( this ).dialog( "close" );
            }
        },
        position: {
            my: "center",
            at: "center",
            of: $("body"),
            within: $("body")
            }

    }).height('auto');// end dialog
}
function msgConfirm(msg){
        $("#msg").html(msg.replace(/\r|\n/gi,"<br>"));
        $("#message").dialog({
            resizable: false,
            width: 500,
            height: 'auto',
            modal: true,
            closeOnEscape: true,
            resizable: false,
            draggable: true,
            buttons: {
                " 확인 ": function() {
                    $( this ).dialog( "close" );
                    location.href= "/ejuv/login?attribute=logOut&fake="+new Date();             
                },
                " 닫기 ": function() {
                    $( this ).dialog( "close" );
                }
            }

        });// end dialog
    }
function setToken(token) {
    $("#token").val(token);
}
function getToken() {
    return $("#token").val();
}
</script>
</head>
<body>
<div id="message" style="display:none;" title="알림"><table align="center" style="font-size:9pt;"><tr><td valign="bottom"><div id="msg"></div></td></tr></table></div>
<input id="token" name="token" type="hidden"/>
<iframe name="Main" scrolling="auto" src="/ejuv/login?attribute=login" style="position: absolute; width:100%; height:100%; border: none"></iframe>
</body>
</html>

【问题讨论】:

  • 这可能是因为 hidden input 中的值是使用 Javascript 动态设置的,这可能是 CSRF 令牌。如果是这种情况,您可能需要Selenium 来抓取数据。

标签: python html beautifulsoup web-crawler


【解决方案1】:

我认为你的意思是你需要进入 iframe 在这种情况下使用 iframe src 值直接

http://obscured_info/ejuv/login?attribute=login

然后您正在使用 iframe 文档。

这个链接被传递给请求(见深红色矩形)

【讨论】:

  • 看这个here
  • @CodeIt 我担心使用实际链接,因为 OP 努力掩盖一些信息。但是,如果他们不介意完整链接,我将接受建议的编辑。
  • @QHarr 我会试试这个方法!!
  • @QHarr 你能告诉我链接是如何工作的,我在帖子中提到的那个没有工作吗?
  • 有效的链接是指向 iframe 内的文档的链接,即登录文档。 iframe 是它自己的browsing context。如果您通过请求检查来自原始 url 的响应,则不会加载 iframe 文档,因此响应中只有“shell”iframe 标记。
猜你喜欢
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 2019-05-16
  • 1970-01-01
  • 2021-06-08
  • 2021-05-05
  • 1970-01-01
  • 2017-02-20
相关资源
最近更新 更多