Please see my small code ( parsing html)
The following code extracts URLs from a webpage. It is working fine for most of the URLs. But not for some, like
http://www.sun.com/java
http://www.kraftfoods.com/
http://www.kitchen-bath.com/
Actually , I observed for these URLs, they are getting redirected. How can I over come this?
Thanks.
Note : there is some redundant code in the program.
import java.io.*;
import java.util.regex.*;
import java.net.*;
import java.util.*;
import java.lang.reflect.*;
import javax.swing.text.html.*;
import javax.swing.text.*;
class Out
public static String[] getLinks(String uriStr) {
List result = new ArrayList();
try {
URL locator = new URL(uriStr);
URLConnection connection = locator.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461)");
connection.connect();
// BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
Reader rd = new InputStreamReader(connection.getInputStream());
// Parse the HTML
EditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(rd, doc, 0);
// Find all the A elements in the HTML document
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
String link = (String)s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
// Add the link to the result list
result.add(link);
it.next();
} catch (MalformedURLException e) {
System.out.println("In Out.java");
System.out.println(e);
e.printStackTrace();
} catch (BadLocationException e) {
System.out.println("In Out.java");
System.out.println(e);
e.printStackTrace();
} catch (IOException e) {
System.out.println("In Out.java");
System.out.println(e);
e.printStackTrace();
// Return all found links
return (String[])result.toArray(new String[result.size()]);
public static void main(String[] args)
String links[] = getLinks(args[0]);
System.out.println(links.length);
for(int i = 0 ; i < links.length ; i++)
System.out.println(links);
I made the following changes.Still it is not working.
URL locator = new URL(uriStr);
HttpURLConnection connection = (HttpURLConnection)locator.openConnection();
connection.setInstanceFollowRedirects(true);
Can anyone help me??
Thanks.
Similar Messages
-
I have an issue installing photoshop CC trial, I currently have elements and wanted to see the differences before buying, when installing through the creative cloud app I get the error message Exit Code: 7 Please see specific errors below for troubleshooting. For example, ERROR: DW041 ... -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 1 error(s)
ERROR: DW041: INSTALLDIR Volume D:\ doesn't exist. ------------------------------------------------------------------------------------- System Requirements and it will not install, It says cant find the path D: im not sure why because as far as I can see its set to install on drive C: which is where I want it!Exit Code: 6, Exit Code: 7 Installation Errors - http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
Troubleshoot with install logs | CS5, CS5.5, CS6 - http://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html for information on how to review your installation logs -
Exit Code: 16
Please see specific errors below for troubleshooting. For example, ERROR: DW039 ...
-------------------------------------- Summary --------------------------------------
- 0 fatal error(s), 1 error(s)
ERROR: DW039: Failed to load deployment FileHi,
Please check this link: http://helpx.adobe.com/x-productkb/global/installation-launch-log-errors-creative.html
Thank You
Arjun -
Failed to install Ligthroom CC Exit Code: 9999 Please see specific errors below for troubleshooting. For example, ERROR: Summary 0 fatal error(s), 0 error(s) Mac
Exit Code: 6, Exit Code: 7 Installation Errors - http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
Troubleshoot with install logs | CS5, CS5.5, CS6 - http://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html for information on how to review your installation logs -
Exit Code: 7
Please see specific errors below for troubleshooting. For example, ERROR: DW013 ...
-------------------------------------- Summary --------------------------------------
- 0 fatal error(s), 6 error(s)
ERROR: -------------------- BEGIN - Initialization Failures - BEGIN --------------------
ERROR: Fatal error initializing from proxy files.
ERROR: The following proxy files could not be loaded
ERROR: /tmp/AB24A935-0FB4-4D57-A6C8-73C0BF15A96E/proxy.xml
ERROR: -------------------- END - Initialization Failures - END --------------------
ERROR: DW013: Cannot initialize payload sessioncs5,cs5.5: https://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
lightroom: http://helpx.adobe.com/lightroom/kb/exit-code-7-displays-installing.html
photoshop elements 13: https://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-installation-errors-exit- codes-6-7.html
premiere elements: http://helpx.adobe.com/premiere-elements/kb/updated-installation-instructions-premiere-ele ments.html -
I have tried downloading about 6 times and this is the message I keep getting. Pls. tell me what I am doing wrong
Exit Code: 7
Please see specific errors below for troubleshooting. For example, ERROR:
-------------------------------------- Summary --------------------------------------
- 0 fatal error(s), 2 error(s)
ERROR: This installer does not support installation on a 64-Bit Windows operating system. Please download the 64-Bit version of Photoshop Elements.
ERROR: System check returned with error : 6I have tried downloading about 6 times and this is the message I keep gettingExit Code: 6, Exit Code: 7 Installation Errors - http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
Troubleshoot with install logs | CS5, CS5.5, CS6 - http://helpx.adobe.com/creative-suite/kb/troubleshoot-install-logs-cs5-cs5.html for information on how to review your installation logs -
i cannot install the newer version
i got this :
Exit Code: 7
Please see specific errors below for troubleshooting. For example, ERROR:
-------------------------------------- Summary --------------------------------------
- 0 fatal error(s), 0 error(s)Code 6 & Code 7 http://helpx.adobe.com/creative-suite/kb/errors-exit-code-6-exit.html
AND JUST FOR MAC USERS - Some 10.9.3 links
-Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
-more Mac 10.9.3 https://forums.adobe.com/thread/1491469
-Enable Mac Root User https://forums.adobe.com/thread/1156604
-more Root User http://forums.adobe.com/thread/879931
-and more root user http://forums.adobe.com/thread/940869?tstart=0 -
Please see my code and helpme out pls
//Making Circle here
gridx=20;
gridy=20;
num=0;
for (var i=0;i < 10;i++)
for (var j=0;j < 10;j++)
dot.duplicateMovieClip("dot"+num,num);
mc=this["dot"+num];
mc._x=gridx*i;
mc._y=gridy*j;
num++;
dot._visible=0;
// here i make plain circle, but problam is my all circle
open in fornt side, i want to that all my circle in background
//hide all selection MovieClip
for(i=1; i<=100; i++){
this.createEmptyMovieClip("test_mc"+i,
this.getNextHighestDepth());
this["test"+i]._visible = false;
// here i make fill circle mc, all hide with this code, but
problam is all circle come in background
//selection area
_root.onMouseDown = function() {
sel = this.createEmptyMovieClip("sel", 1);
sel.startx = _xmouse; // we need to reference these later,
so add them as properties of the selection clip
sel.starty = _ymouse;
this.onEnterFrame = function() {
with(sel){
clear();
lineStyle( 1, 000000, 100 );
moveTo(sel.startx, sel.starty);
lineTo(_xmouse, starty);
lineTo(_xmouse, _ymouse);
lineTo(sel.startx, _ymouse);
lineTo(sel.startx, sel.starty);
_root.onMouseUp = function() {
_root.select(sel.startx,sel.starty,sel._xmouse,sel._ymouse);
// call the selection function
removeMovieClip(sel);
this.onEnterFrame = undefined;
_root.select =
function(x1:Number,y1:Number,x2:Number,y2:Number){
// in case you dragged the selection box from right to left
or bottom to top, we need
// to work out the top left and bottom right coordinates..
var sx = Math.min(x1,x2);
var ex = Math.max(x1,x2);
var sy = Math.min(y1,y2);
var ey = Math.max(y1,y2);
for(var item in this){ // loop through all items in the
_root
if(typeof(this[item])=="movieclip"){ // if the current item
is a movieclip..
this[item]._visible = isInside(this[item],sx,sy,ex,ey);
function
isInside(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):Boolean{
// check whether the selection coordinates enclose the mc
coordinates
return (x1<=mc._x && x2>=mc._x+mc._width
&& y1<=mc._y && y2>=mc._y+mc._height);
// here u can find selection option, selection option is
wroking, but same problam, it work in background, & hide my all
MC (that Plain Circle also) and highlight only which we select
// Some brif here:
i want to create plain circle in background, after that some
one want to slecte that palin circle highlight that circle only
with fill circle ( for better explaination see my fla file which is
attach here
Please see this
Pls pls help me out
thanks
praful damaniafor better explaination pls see my fla file which is attache
there & I have some quation about it as under
1) here i make fill circle mc, all hide with this code, but
problam is all circle come in background
2) here i make fill circle mc, all hide with this code, but
problam is all circle come in background
3) here u can find selection option, selection option is
wroking, but same problam, it work in background, & hide my all
MC (that Plain Circle also) and highlight only which we select
i want to create plain circle in background, after that some
one want to slecte that palin circle highlight that circle only
with fill circle
thanks for reply
Praful Damania -
How to make my code more modular? Please see thread.
Question
How do I go about doing something like the example below? Please see example.
Example of current form
My current method of painting to a component is as follows:
public class Pane extends JPanel{
public void paint(Graphics g){
... (all painting is done in here) ...
}What I want to do is break the painting method into multiple methods and or classes, so my program is less cluttered and more modular. For instance,
Method 1
public class Pane extends JPanel{
public void paintCustomButtons(Graphics g){
// (all painting of my custom buttons are done in here) ...
public void paintOtherComponents(2Graphics g){
// (all other painting is done in here) ...
}Or should I break it up into classes, the headers of those classes are:
Method 2
public class ButtonComponents extends JComponent
public class OtherComponents extends JComponent
//and then have a panel that contains all those components like so
public class Pane extends JPanel{
Pane(){
add(ButtonComponents);
Final Questions
How can I break my painting code up? Is it possible to do method 1 or 2? If so, which would you suggest? Or would you suggest another way of organizing blocks of code?
-Thanks for any suggestions as they are much appreciated
Edited by: watwatacrazy on Feb 6, 2010 10:17 AMTo break the paint method up you can always do the following:
@Override
public void paintComponent(Graphics g) {
g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
paintAxis(g2d);
paintCrossHair(g2d);
public void paintCrossHair(Graphics2D g2d) {
public void paintAxis(Graphics2D g2d) {{
}Edited by: calypso on Feb 6, 2010 1:39 PM -
Exit Code: 7
Please see specific errors and warnings below for troubleshooting. For example, ERROR: DW041 ... WARNING: DW017 ...
-------------------------------------- Summary --------------------------------------
- 0 fatal error(s), 1 error(s), 1 warning(s)
WARNING: DW017: PayloadPolicyNode.SetAction: DN payload {9E0AF030-AC6B-11E0-8837-00215AEA26C9} Microsoft Visual C++ 2010 Redistributable Package (x86) 10.0.40219.1 is required by {B8ADDCBD-30D9-4366-AE25-089CEF76C8E1} Suite Shared Configuration CS6 3.0.0.0 but isn't free. Reason: Required dependency
ERROR: DW041: INSTALLDIR Volume E:\ doesn't exist.Errors "Exit Code: 6," "Exit Code: 7"
Mylenium -
My iPhone4s has been stolen,and it has been repaired in somewhere!Once the stealer had a new iPhone,I couldnot have my iPhone forever!what should I do?I am inChina,I have call police.But police seem to see it small.please help me,it has been my second lost iPhone4s
There is nothing to do. You have done all you can.
Buy a new iphone.
Buy a different phone.
Do without a phone. -
Exit Code: 6 Please see specific errors and warnings below for troubleshooting. For example, ERROR: DW050 ... Exit Code: 6 Please see specific errors and warnings below for troubleshooting. For example, ERROR: DW050 ... -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 2 error(s), 0 warning(s) ERROR: DW050: The following payload errors were found during install: ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x64): Install failed ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x86): Install failed -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 2 error(s), 0 warning(s) ERROR: DW050: The following payload errors were found during install: ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x64): Install failed ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x86): Install failed
PS CS6,Please help!Errors "Exit Code: 6," "Exit Code: 7"
Mylenium -
Some email images do not show while using the icloud web app. I can see the images on my IOS devices and in gmail but I only see a small gray box in the icloud web mail app. Load HTML images is checked in preferences. Is there a solution to this issue?
I've seen the opposite issue. My wife recieved an email with jpg attachments. She couldn't see or print them on her iPhone 4S but they showed up fine in iCloud or in the mail app. I had her forward the email to herself and then they showed up. I assume there is an issue with how Apple is processing the attachments and resending causes them to get reformatted in a way that makes them easier to handle.
So yeah. Seems like some bugs. Hope Apple fixes them soon. -
What is it? Exit Code: 34 Please see specific errors below for troubleshooting.
Exit Code: 34
Please see specific errors below for troubleshooting. For example, ERROR:
-------------------------------------- Summary --------------------------------------
- 1 fatal error(s), 0 error(s)
FATAL: Payload 'Camera Profiles Installer 8.0.0.22 {3F023875-4A52-4605-9DB6-A88D4A813E8D}' information not found in Media_db.
who can tell me???Without proper system information nobody can tell you much. This error usually indicates that a previous install of some Adobe program has introduced an incompatible component and it's blocking the new install. as a start run teh cleaner tool an d try again.
Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
Mylenium -
Outlook code in html please harry up
looking for code in html to run the outlook client but it have to include the navigation bar and the public folder.
and yes i have seen the sample in sap.help.com and in the sdn but it is not enough.
Message was edited by: Yoav Toussia CohenA simple search at Google will lead you to this KB article: http://support.microsoft.com/?kbid=281618
As you can see, my page can be improved a lot! After all, it was written 4 years ago and a quick hack to see how it worked.
In version 4.5 of the portal, this was how Outlook was integrated. smile I hope you are not going for this type of integration today.
Regards,
Mikael
Maybe you are looking for
-
ADF Toystore question: no blank row in viewobject on "Add" JSP form
A new thread based on Suggestions for Automatic Commit/Rollback In the ADF Toystore application, I did not notice the blank row behavior in the user registration section like we encountered in the other thread posting (Suggestions for Automatic Commi
-
Problem with Syncing configuration to our CSM
Recently we have had problems syncing between our pair of redundant CSM's. Here is the behavior we observe when we run the command on one of our 6500. ! config 6500-2 module ContentSwitchingModule 2 ft group 1 vlan 4 priority 10 alt 20 ! config 650
-
All apps gone after forced restart of iPad
Hello, I was just developing a bit with my iPad and after the debugger got hang I had to restart my iPad by holding down the home button and the lock button for some seconds. After the iPad was booted up again, i noticed that all apps (expect the bui
-
i loaded bb desktop software on my pc to use media sync to manage my music on my phone,when i go to syncthe music it keeps saying itunes not installed. Do i need to have an itunes app on my phone? If i do,how do i get one?
-
Import Flickr to iPhoto?
Does anyone know if there's a way to get all of your existing Flickr photo sets to show up in iPhoto? I'd like to manage my Flickr stream from iPhoto, but I don't want to have to recreate them in iPhoto to get them to show up.