473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

With LWP; wish to print a part of a page in browser

5 New Member
Am using LWP module.
I wish to read a page and print a part of it.
I want t read first 300 characters of <div id="bodyContent"> written inside the html page.

Code I am using :
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use DBI;
  4. use CGI;
  5. use LWP::Simple;
  6. use LWP::UserAgent;
  7. use DateTime::Format::Strptime;
  8. use JSON;
  9. use HTML::Template;
  10. use HTML::Parser;
  11. use HTML::Entities;
  12.  
  13.  
  14. $q = new CGI;
  15. print "Content-type: text/html\n\n";
  16.  
  17. my $url = '------site url comes here ----';
  18.  
  19.   use LWP::Simple;
  20.   my $content = get $url;
  21.   die "Couldn't get $url" unless defined $content;
  22.  
  23.   #$description = &convert_to_page(substr($content,0,650)); 
  24.   print $content;
  25.  
  26. 1;
  27.  
Apr 16 '09 #1
1 1677
eWish
971 Recognized Expert Contributor
What part are you having problems with? Also, since you are using the CGI.pm have it print your header for you.
Expand|Select|Wrap|Line Numbers
  1. print $q->header();
instead of:
Expand|Select|Wrap|Line Numbers
  1. print "Content-type: text/html\n\n";
You only have to have this once in your script for it to work. So, I would suggest that your remove the second one you have listed.
Expand|Select|Wrap|Line Numbers
  1. use LWP::Simple;
I can't see what you are doing in this sub "&convert_to_page" but, you can use substr to get the first 300 characters by changing the 650 to 300.
Expand|Select|Wrap|Line Numbers
  1. my $page = substr($content,0,300);
  2. print $page;
You could also use a regex to if you wish.

--Kevin
Apr 17 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Woogie | last post by:
When running the sample code below without a proxy the GET returns the expected data. When run with the $proxy uncommented the GET returns the content of the login page for the site being...
0
by: Chandra | last post by:
Hello gurus, I am using LWP::Useragent perl module to get a url from the www. Code snippet: #!perl -w use LWP::UserAgent; LWP::Debug::level('+'); $ua = new LWP::UserAgent || die "$!";
0
by: Travis | last post by:
This is an example of LWP that I found on one of the perl docs pages. use LWP 5.64; this line is causing an external error. Does that mean I don't have LWP on my server or is something else...
3
by: suchindra | last post by:
The following is my very simple script : </script> #!/usr/bin/perl use strict; use LWP::UserAgent; my $url = "<My Web Server IP : PORT Number>"; my $browser =...
0
by: sharif | last post by:
Anyone could help me out for n=my code ......I have written following code ,Here i m able to get and post the form successfuly..but after posting im not gettng proper response content... ...
3
by: pplers | last post by:
it's an example. I want a script to print the real url behind a lix.in one so i tried these: use LWP::UserAgent; use LWP::UserAgent; my $ua = new LWP::UserAgent; my $response =...
3
by: powersakthi | last post by:
Hi All, I am using LWP::UserAgent and HTML::TreeBuilder to communicate to the below site Here is the website map: https://secure.server.com/index.htm which asks for two fields user_id...
4
by: kkamath | last post by:
Hi, I use LWP::UserAgent to automate windows login process. I set the credentials using $ua->credentials("host:port","realm","id","password"); but it fetches only the current page requested. It...
3
by: cketcham | last post by:
All, I have the following code: use 5.010; use LWP::UserAgent; use URI::URL; use LWP::Debug qw(+); my $browser = LWP::UserAgent->new();
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.