Author | RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
Hello I have been trying to do the timed challenges in JS. I have completed up to 6. I tried doing timed 6 in JS but trying to get the XMLHttpRequest() to get the data off of google is tricky (unless I'm using the wrong function...?) Anyway, I thought it would be practice to try doing it in a different language, so I chose Python.
I can log into the site and get the page data off of timed6/index.php.
Code linkNum = re.search("[a-z]{1,}(?= result)", hbh)
word = re.search("[a-z]{1,}(?=<\/strong>)", hbh)
side note: I also notice that the word var is not correct but I will fix it later (ex: if word = google then it finds google, but if word = good bye then only bye is found.)
Anyway, when it finds the regex patterns I get:
Code <_sre.SRE_Match object at 0x00E42368>
How can I print this in the shell so I see the actual word not its location?
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
Never mind, using findall() function.
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
fixed the findall() strings to
Code linkNum = re.findall("\w+(?= result from)", hbh)
word = re.findall("\w+(?=<\/strong> and post)", hbh)
looks neater but stills doesn't grab the spaces if in ex: "denial of service" only gets service.
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
Edited by elmiguel on 27-07-09 19:42 |
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
Ok, if I have a page opened and I request another, how can I store that data?
for example:
Code Python using urllib2:
reqPage = 'http://www.site.com'
req2 = urllib2.Request(reqPage, None)
pData = #how do I search through this request for my data?
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
elmiguel wrote:
Ok, if I have a page opened and I request another, how can I store that data?
for example:
Code Python using urllib2:
reqPage = 'http://www.site.com'
req2 = urllib2.Request(reqPage, None)
pData = #how do I search through this request for my data?
1- To store the data you need to receive it first as you know, and then store it somewhere (a variable maybe (?))
2- to search through the request:
Code
req = Request('www.blabla.com', None, headers) #headers is where cookies goes
response = urlopen(req) #open the site
site2string = str(response.read()) #reading the responce as a single string
find_data = site2string.find('YOUR DATA MOHAHAHAH') #search for your data
http://www.java2s. . .sition.htm
Edited by Demons Halo on 27-07-09 19:44 |
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
cool thanks reading now,
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
It seems like I am having trouble retrieving data from here:
Code
google = 'http://www.google.co.uk/search?q=' + word[0]
if I just do http://www.google.com and store the data its does it fine, but not when I do it with search?q= and the end of it.
Any suggestions?...
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
Wow, you posted over 85% of the posts in this thread.
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
sad isn't......
But I have fixed most of my issues so far I am trying to figure out how to print out an arrays' index though a var
ex:
Code
intLink = 2
print theLinks[intLink]
gives and error in python:
Code Traceback (most recent call last):
File "I:/HBH Work Files/timed6_pyA.py", line 32, in <module>
print theLinks[intLink]
TypeError: list indices must be integers, not str
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
arrays in python are called "lists" =P
http://stackoverf. . .or-objects
use that with a variable to get the index value ^^
Edited by Demons Halo on 27-07-09 22:06 |
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
hmm weird none of them are working. I have tried all the examples, but for some reason it will not take a variable as an integer it reads it as a string. And for some reason my last for loop is not running....
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
well it works when I do it :S
post your code and let me have a look =)
|
 |
Author | RE: RegEx in python questions |
SySTeM Member

Posts: 1524 Location: England, UK
Joined: 27.07.05 Rank: HBH Guru | |
Demons Halo wrote:
well it works when I do it :S
post your code and let me have a look =)
He can't really post his code as it's for beating a mission, if he does then people can just copy it and use it themselves :-/
|
 |
Author | RE: RegEx in python questions |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
system_meltdown wrote:
Demons Halo wrote:
well it works when I do it :S
post your code and let me have a look =)
He can't really post his code as it's for beating a mission, if he does then people can just copy it and use it themselves :-/
well he can either pm me or just post the loop that is not working so someone could help him fix the syntax =P
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
I can post an example of what I am trying to do:
Code
#Python 2.6.1
intNum = 2 #the random number using 2 for purpose
aArray = ['item1','item2','item3'] # etc, etc..
print aArray[intNum] #cannot work because its reading intNum as a string
Since I do not know the number right a way nor will it work if I hard code it, I need it to grab the random number that is given. The only way that I know of is to store it in a variable. Which is not hard, but, I need to know how to pass the variable in the index as a integer not a string.
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
Isn't it possible to do int(intNum) to get it as an integer?
|
 |
Author | RE: RegEx in python questions |
Demons Halo Member

Posts: 261 Location: Sweden
Joined: 26.03.09 Rank: Apprentice | |
Code
>>> wtf = 2
>>> list= ['bla 1', 'bla 2', 'bla 3']
>>> print list[wtf]
bla 3
and in case the number you're grabbing is a tiny bit of a string, then use:
Code
int(variable) #This will convert the string into integer, make sure you have only numbers as a value of this variable
str(variable) #To convert a variable value into a string
Edited by Demons Halo on 28-07-09 19:33 |
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
You Rock!!!!!
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
elmiguel Member

Posts: 165 Location: Your Computer
Joined: 12.12.07 Rank: God | |
Ok, I am at the final stage of this challenge, all I need help with now is how to post back the data to the same url.....
do I have to subit another request? (I do not think that would be it right, wouldn't it just grab a new page?)
do I just open the page again and post back? (not sure if python keeps it open or not)
The philosophy of one century is the common sense of the next. -Fortune Cookie
I would like to thank a few friends that I have made here that helped me and deserve to be mentioned:
System_Meltdown, Futility, nvrlivenvrdie, Mastergamer, TrueHacker, S1L3NTKn1GhT, Reelix, ynori7, Demons Halo, kryptor
oh and
Mordak, my long lost brother from across the pond!
|
 |
Author | RE: RegEx in python questions |
Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | |
elmiguel wrote:
Ok, I am at the final stage of this challenge, all I need help with now is how to post back the data to the same url.....
do I have to subit another request? (I do not think that would be it right, wouldn't it just grab a new page?)
do I just open the page again and post back? (not sure if python keeps it open or not)
Basic http. Learn it.
|
 |