RegEx in python questions
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.
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:
```markup<_sre.SRE_Match object at 0x00E42368>```
How can I print this in the shell so I see the actual word not its location?
elmiguel wrote: Ok, if I have a page opened and I request another, how can I store that data?
for example:
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:
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.com/Code/Python/String/Stringsearchsearchforposition.htm
It seems like I am having trouble retrieving data from here:
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?…
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:
intLink = 2
print theLinks[intLink]
gives and error in python:
File "I:/HBH Work Files/timed6_pyA.py", line 32, in <module>
print theLinks[intLink]
TypeError: list indices must be integers, not str```
arrays in python are called "lists" =P
use that with a variable to get the index value ^^
system_meltdown wrote: [quote]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 :-/[/quote]
well he can either pm me or just post the loop that is not working so someone could help him fix the syntax =P
I can post an example of what I am trying to do:
#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.
>>> 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:
```markup
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
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)
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.
Demons Halo wrote: [quote]COM wrote: Basic http. Learn it.
This has nothing to do with his question =P (as far as I know ^^)…
simply you need to request a new page with your answer added to the url using the given keys in the challenge description.[/quote] If you'd have learnt basic http then you would've known that it had a fucking lot to do with his question, goddamn substitute teacher.
COM wrote: [quote]Demons Halo wrote: [quote]COM wrote: Basic http. Learn it.
This has nothing to do with his question =P (as far as I know ^^)…
simply you need to request a new page with your answer added to the url using the given keys in the challenge description.[/quote] If you'd have learnt basic http then you would've known that it had a fucking lot to do with his question, goddamn substitute teacher.[/quote]
:( rofl… substitute teacher xD stop shoving this basic http stuff up everybody's ass! =P I know it's a must, but it's sure boring as hell …
I love you btw…
Demons Halo wrote: :( rofl… substitute teacher xD stop shoving this basic http stuff up everybody's ass! =P I know it's a must, but it's sure boring as hell …
I love you btw…
I'll stop shoving it up everybody's ass when they stop bending over for it. That includes you and please, shave that hairy ass of yours. The http will get lost on its way in, which is probably why it still hasn't reached you.
COM wrote: I'll stop shoving it up everybody's ass when they stop bending over for it. That includes you and please, shave that hairy ass of yours. The http will get lost on its way in, which is probably why it still hasn't reached you.
hahahahaha fair enough! but how did you know my ass is hairy? :S did chocolate tell you?
elmiguel wrote: Wow thanks COM I don't know if I ever would have figured that out.. Wow you are amazing!! I know I am, good thing I'm here to save you. Who knows where you'd ever be without my help, support and assistance. Knowing how immensely great, generous and awesome I am, I hereby allow you to build a small shrine in my honor where you can come to worship me.