473,581 Members | 3,046 Online
Bytes | Software Development & Data Engineering Community
+ 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 1684
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_pa ge" 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
12645
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 accessed. The site in the code is valid for ease of testing. I also am including the LWP debug info for each attempt. Can anyone explain this behavior...
0
2270
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
2638
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 wrong? Let me know if this works for you. ############# use strict; use warnings; use LWP 5.64;
3
12016
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 = LWP::UserAgent->new(keep_alive => 5, timeout => 10, agent => 'unimportant',);
0
2542
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... #!usr/bin/perl -w use strict; use LWP; use LWP::Simple; use LWP::UserAgent; use HTML::Form; use Switch; use HTTP::Cookies;
3
2108
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 = $ua->post('http://lix.in/53fe67',{ tiny => '53fe67', submit => 'continue',}); my $con = $response->content;
3
2175
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 user_pwd then submit button the form is submitted to https://secure.server.com/login.asp
4
4226
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 fails for subsequent requests and pops up the windows form again to supply the credentials. I have created a cookie jar too but this doesnt help as the...
3
3327
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
7809
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8183
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6569
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3809
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.