473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having problems with urlparser concatenation

I'm working on a basic web spider, and I'm having problems with the
urlparser.
This is the effected function:
------------------------------
def FindLinks(Websi te):
WebsiteLen = len(Website)+1
CurrentLink = ''
i = 0
SpliceStart = 0
SpliceEnd = 0

LinksString = ""
LinkQueue = open('C:/LinkQueue.txt', 'a')

while (i < WebsiteLen) and (i != -1):

#Debugging info
#print '-----'
#print 'Length = ' + str(WebsiteLen)
#print 'SpliceStart = ' + str(SpliceStart )
#print 'SpliceEnd = ' + str(SpliceEnd)
#print 'i = ' + str(i)

SpliceStart = Website.find('< a href="', (i+1))
SpliceEnd = (Website.find(' ">', SpliceStart))

ParsedURL =
urlparse((Websi te[SpliceStart+9:( SpliceEnd+1)]))
robotparser.set _url(ParsedURL. hostname + '/' +
'robots.txt')
robotparser.rea d()
if (robotparser.ca n_fetch("*",
(Website[SpliceStart+9:( SpliceEnd+1)])) == False):
i = i - 1
else:
LinksString = LinksString + "\n" +
(Website[SpliceStart+9:( SpliceEnd+1)])
LinksString = LinksString[:(len(LinksStri ng) - 1)]
#print 'found ' + LinksString
i = SpliceEnd

LinkQueue.write (LinksString)
LinkQueue.close ()
------------------------------
Sorry if it's uncommented. When I run my program, I get this error:
-----
Traceback (most recent call last):
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 120, in <module>
FindLinks(Websi te)
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 84, in FindLinks
robotparser.rea d()
File "C:\Program Files\Python25\ lib\robotparser .py", line 61, in read
f = opener.open(sel f.url)
File "C:\Program Files\Python25\ lib\urllib.py", line 190, in open
return getattr(self, name)(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 451, in
open_file
return self.open_local _file(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 465, in
open_local_file
raise IOError(e.errno , e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia.o rg\\robots.txt'

Note the last line 'en.wikipedia.o rg\\robots.txt' . I want
'en.wikipedia.o rg/robots.txt'! What am I doing wrong?

If this has been answered before, please just give me a link to the
proper thread. If you need more contextual code, I can post more.

Nov 9 '06 #1
3 1596
In <11************ **********@b28g 2000cwb.googleg roups.com>, i80and wrote:
return self.open_local _file(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 465, in
open_local_file
raise IOError(e.errno , e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia.o rg\\robots.txt'

Note the last line 'en.wikipedia.o rg\\robots.txt' . I want
'en.wikipedia.o rg/robots.txt'! What am I doing wrong?
You don't have that file on you local computer. :-)

If you look at the messages above you'll see there's a function
`open_local_fil e()` involved. This function is chosen by `urllib` because
your path looks like a local file, i.e. it lacks the protocol information.
You don't want 'en.wikipedia.o rg/robots.txt', you want
'http://en.wikipedia.or g/robots.txt'!

Ciao,
Marc 'BlackJack' Rintsch
Nov 9 '06 #2
At Thursday 9/11/2006 20:23, i80and wrote:
>I'm working on a basic web spider, and I'm having problems with the
urlparser.
[...]
SpliceStart = Website.find('< a href="', (i+1))
SpliceEnd = (Website.find(' ">', SpliceStart))

ParsedURL =
urlparse((Webs ite[SpliceStart+9:( SpliceEnd+1)]))
robotparser.set _url(ParsedURL. hostname + '/' +
'robots.txt' )
-----
Traceback (most recent call last):
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 120, in <module>
FindLinks(Websi te)
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 84, in FindLinks
robotparser.rea d()
File "C:\Program Files\Python25\ lib\robotparser .py", line 61, in read
f = opener.open(sel f.url)
File "C:\Program Files\Python25\ lib\urllib.py", line 190, in open
return getattr(self, name)(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 451, in
open_file
return self.open_local _file(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 465, in
open_local_fil e
raise IOError(e.errno , e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia. org\\robots.txt '

Note the last line 'en.wikipedia.o rg\\robots.txt' . I want
'en.wikipedia. org/robots.txt'! What am I doing wrong?
No, you don't want 'en.wikipedia.o rg/robots.txt'; you want
'http://en.wikipedia.or g/robots.txt'
urllib treats the former as a file: request, here the \\ in the
normalized path.
You are parsing the link and then building a new URI using ONLY the
hostname part; that's wrong. Use urljoin(ParsedU RL, '/robots.txt') instead.

You may try Beautiful Soup for a better HTML parsing.

--
Gabriel Genellina
Softlab SRL

_______________ _______________ _______________ _____
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Nov 9 '06 #3
Thank you! Fixed my problem perfectly!
Gabriel Genellina wrote:
At Thursday 9/11/2006 20:23, i80and wrote:
I'm working on a basic web spider, and I'm having problems with the
urlparser.
[...]
SpliceStart = Website.find('< a href="', (i+1))
SpliceEnd = (Website.find(' ">', SpliceStart))

ParsedURL =
urlparse((Websi te[SpliceStart+9:( SpliceEnd+1)]))
robotparser.set _url(ParsedURL. hostname + '/' +
'robots.txt')
-----
Traceback (most recent call last):
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 120, in <module>
FindLinks(Websi te)
File "C:/Documents and Settings/Andrew/Desktop/ScoutCode-0.09.py",
line 84, in FindLinks
robotparser.rea d()
File "C:\Program Files\Python25\ lib\robotparser .py", line 61, in read
f = opener.open(sel f.url)
File "C:\Program Files\Python25\ lib\urllib.py", line 190, in open
return getattr(self, name)(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 451, in
open_file
return self.open_local _file(url)
File "C:\Program Files\Python25\ lib\urllib.py", line 465, in
open_local_file
raise IOError(e.errno , e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified:
'en.wikipedia.o rg\\robots.txt'

Note the last line 'en.wikipedia.o rg\\robots.txt' . I want
'en.wikipedia.o rg/robots.txt'! What am I doing wrong?

No, you don't want 'en.wikipedia.o rg/robots.txt'; you want
'http://en.wikipedia.or g/robots.txt'
urllib treats the former as a file: request, here the \\ in the
normalized path.
You are parsing the link and then building a new URI using ONLY the
hostname part; that's wrong. Use urljoin(ParsedU RL, '/robots.txt') instead.

You may try Beautiful Soup for a better HTML parsing.

--
Gabriel Genellina
Softlab SRL

_______________ _______________ _______________ _____
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Nov 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3635
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
1
2346
by: Fahd Khan | last post by:
Hi team! While troubleshooting a crash I had while using BitTorrent where the torrent's target file names didn't fall into the ascii range I was playing around in the interpreter and noticed this behaviour: >>> u'\u12345' + 'foo' u'\u12345foo' >>> u'\u12345' u'foo' u'\u12345foo' >>> u'\u12345' + u'foo'.encode('ascii') u'\u12345foo'
2
6703
by: Daniel Bergquist | last post by:
Consider the following chunk of code: -------------------------------------------------- open (IN, "<:raw", "test2.txt") or die "Can't open test.txt"; chomp($line = <IN>); # Capture excerpt $line =~ m/>(+)/; # Copy first line of excerpt
7
8026
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so something like this: 1) e = (a, b, c, d); // concatenate a,b,c,d into e 2) (a, b, c, d) = e; // get the bits of e into a,b,c, and d For example, in the second case, assume that a,b,c,d represent 2-bit integers, and e represents an 8-bit...
2
1225
by: Adelson Anton | last post by:
Greetings fellow coders. Please check this page for a code which rearranges chess cells: http://s95005072.onlinehome.us/blog/Chess/chess.htm There are 2 problems: 1. It takes quite a bit for the function to run each time. I don't know how to speed it up further. 2. The function runs twice on mozilla browsers for some reason. Any help is greatly appreciated. And hold your flames, this is my first
9
2044
by: Justin M. Keyes | last post by:
Hi, Please read carefully before assuming that this is the same old question about string concatenation in C#! It is well-known that the following concatenation produces multiple immutable String objects for each statement: String a = "a"; a += "b";
33
4666
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most of articles I read from different experts and programmers tell me that their "gut feelings" for using stringBuilder instead of string concatenation is when the number of string concatunation is more then N ( N varies between 3 to max 15 from...
34
2645
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ____________ THE OVERVIEW I don't remember where I picked it up, but I remember reading years ago that the simple, obvious Python approach for string concatenation: x = "a" + "b"
34
3530
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding 200000 strings of 8 char each, string took over 25 minutes while StringBuilder took 40 milliseconds! Can anybody explain such a radical difference?
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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
2
1732
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.