简体   繁体   English

如何从网页中获取数据到 iseries 并使用 Python 使用它

[英]How do I get the data from a webpage into iseries and work with it using Python

I have a list of dr saves details made availaible on our intranet page.我在我们的 Intranet 页面上提供了一份 dr 保存详细信息的列表。

I need to build a utility such thatthe input dates provided,somehow gets the volume and seq number details from the webpage and access the db2 database accordingly.我需要构建一个实用程序,以便提供输入日期,以某种方式从网页获取卷和序列号详细信息,并相应地访问 db2 数据库。

I was thinking/learning pyhon on terms of using bs4 soup to scrape the data on webpage but now how do I get the data into iseries.我正在考虑/学习 pyhon 使用 bs4 汤来抓取网页上的数据,但现在我如何将数据放入 iseries 中。 Is this even possible?这甚至可能吗?

you can use the sql function httpgetclob to read the contents of a web page.您可以使用 sql function httpgetclob来读取 web 页面的内容。

Here is sample code that uses httpgetclob in an sql procedure .这是在sql procedure中使用httpgetclob的示例代码。 The procedure receives the httpgetclob output into a clob variable.该过程将httpgetclob output 接收到clob变量中。 Then it reads 256 byte chunks of that output, writing the chunks to an output file.然后它读取 output 的 256 字节块,将这些块写入 output 文件。

here is the output file:这是 output 文件:

/* test0244 - web page text contents.        */           
                                                          
CREATE OR REPLACE TABLE TEST0244 (
pageName   char(20),
seqnbr   decimal(7,0),
text     char(256) not null default ' ', 
constraint test0244_pk primary key( pageName, seqnbr )    
) ; 

sql procedure that gets the contents of the web page and writes to the output table: sql 过程获取 web 页面的内容并写入 output 表:

/* test0244_getWebPage - get contents of web page.    */ 
/*                       Store in table TEST0244.     */ 

CREATE or replace PROCEDURE test0244_getWebPage( 
 in inPageName char(20), 
 in inUrl    char(256) 
 ) 
  LANGUAGE           SQL
  MODIFIES           SQL DATA
  SET OPTION         COMMIT = *NONE 
BEGIN
declare     vSqlCode decimal(5,0) ; 
declare     sqlCode int DEFAULT 0 ;                      
declare      url varchar(2000) ;                         
declare      webClob clob(500000) ;                      
declare      web_lx int ;                                
declare      bx  int ;                                   
declare      rem int default 0 ; 
declare      segSx int ; 
declare      segLx int ; 
declare      segText varchar(2000) ; 
declare      seqnbr decimal(7,0) default 0 ; 

/* clear current page contents.      */               
delete from  test0244 a                               
where        a.pageName = inPageName ;                
                                                      
set        url = inUrl ;                              
set        webClob = SYSTOOLS.httpGetClob( url, '' ) ;
set        web_lx  = length( webClob ) ;              
set        bx = 1 ;                                   
set        segSx = 256 ;                              
set        seqnbr = 0 ;                               
while( bx <= web_lx ) do                              
set        rem = web_lx - bx + 1 ;                    
set        segLx = case when rem >= segSx             
                        then segSx                    
                        else rem end ;                
set        segText = substr( webClob, bx, segLx ) ;   
set        seqnbr  = seqnbr + 1 ;                     
insert into   test0244  ( pageName, seqnbr, text )    
values( inPageName, seqnbr, segText ) ;               
                                                      
set        bx = bx + segLx ;                          
end while ;
END 

code that calls the procedure:调用该过程的代码:

call   test0244_getWebPage ( 'craigslist      ',   
          'https://newjersey.craigslist.org/')     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM