首页 > 解决方案 > 如何抓取我的拼贴结果网站

问题描述

我想从我的拼贴结果网站收集学生的结果数据 - http://www.bietjhs.ac.in/result2019/GetResult.aspx

所以为此,我使用了requestspython中的模块

import requests
from bs4 import BeautifulSoup
url = 'http://www.bietjhs.ac.in/result2019/Result.aspx'

values = {'__VIEWSTATE':'/wEPDwULLTEwMTgxNzc0MDlkZPl3fGYoB3mixdEklq4qolYFT0kX',
          '__VIEWSTATEGENERATOR':'83531E22',
          '__EVENTVALIDATION':'/wEWAwL1j+SrAgK097CQBgLCi9reAwX5Exu+9wGq1/SB++dfh19a1B4s',
          'txtRollNo':'1804310063'}


respond = requests.post(url = url,data = values)

soup = BeautifulSoup(respond.content,features='html.parser')

print(soup.text)

我的代码解释成功,但站点响应运行时错误。

    
         
             
                运行时错误
        
             
         
             
         
                    

\'/result2019\' 应用程序中的服务器错误。

运行时错误

说明:服务器上发生应用程序错误。此应用程序的当前自定义错误设置可防止远程查看应用程序错误的详细信息(出于安全原因)。但是,它可以被本地服务器机器上运行的浏览器查看。

详细信息:启用此特定错误消息的详细信息 要在远程机器上查看,请在“web.config”配置中创建 <customErrors> 标记 文件位于当前 Web 应用程序的根目录中。然后,该 <customErrors> 标记应将其“mode”属性设置为“Off”。

 
         
        <!-- Web.Config Configuration File --> 
         
        <configuration> 
            <system.web> 
                <customErrors mode="Off"/> 
            </system.web> 
        </configuration>
                      </td> 
                   </tr> 
          
          </table> 
     
                <br> 
                          <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application\'s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br> 
     
                <table width=100% bgcolor="#ffffcc"> 
                   <tr> 
                      <td> 
                          <code><pre> 
     
    &lt;!-- Web.Config Configuration File --&gt; 
     
    &lt;configuration&gt; 
        &lt;system.web&gt; 
            &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt; 
        &lt;/system.web&gt; 
    &lt;/configuration&gt;</pre></code> 
                      </td> 
                   </tr> 
                              </table> 
                <br> 
        </body> 
    </html> 

所以,请让我知道我在哪里做错了。

卷号介于 1804310011 到 1804310064 之间。

标签: seleniumweb-servicesweb-scrapingpython-requests

解决方案


__VIEWSTATE __VIEWSTATEGENERATOR并且__EVENTVALIDATION是服务器应用程序的会话实现。它是动态的,只能使用一次(或几次,在受限上下文中)

您应该执行两个请求:一个GET GetResult.aspx(检索这些参数)和一个POST Result.aspx检索结果。

注意:在继续之前,如果我是你,我会检查是否允许我执行这样的脚本。


推荐阅读