Python script click link

Punkachu
9 years ago

0

Hey guys !

How can I remotly click on a link located in a given web link ?
I tried using selenium .

Tkanks in advance XD !

17replies
5voices
544views
PNTSTR
9 years ago | edited 9 years ago

0

You want open page with Python and find there link to another page and open it with Python again?

Punkachu
9 years ago

0

No I want to open up the link I already have then send a get request to another link wich I already have.
Because there is a timer between the moment I click on it and the moment it is receiving the get request.

PNTSTR
9 years ago | edited 9 years ago

0

Not a best way, but works. Is it what you need? (Python 2.7)

```import socket

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((‘your_first_host’, 80))
mysock.send(‘GET your_first_page HTTP/1.0\n\n’)

while True:
data = mysock.recv(512)
if ( len(data) < 1 ) :
break
print data;

mysock.close()

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((‘your_second_host’, 80))
mysock.send(‘GET your_second_page HTTP/1.0\n\n’)

while True:
data = mysock.recv(512)
if ( len(data) < 1 ) :
break
print data;

mysock.close()```

dloser
9 years ago

0

@Punkachu**, try explaining more clearly what you want to do. So far what you have said doesn’t make any sense.

Punkachu
9 years ago

0

It’s okay I found a upper language version to solve it, I’ve just use webbrowser import as it follow :
```
import requests
import webbrowser
from datetime import datetime

def get_request(result):
#conn = requests.get(“http://challenge01.root-me.org/programmation/ch1/ep1_v.php?result=” + str(result))
#print conn.status_code
webbrowser.open(“http://challenge01.root-me.org/programmation/ch1/ep1_v.php?result=” + str(result))

def suite(n):
start = datetime.now()
webbrowser.open(‘http://challenge01.root-me.org/programmation/ch1/’)
Un = 861
Unp1 = 861
for x in range(0, n):
Un, Unp1 = Unp1, ((-33 + Un) - (x * 34))
print datetime.now()-start
print “Result :”, Unp1
get_request(Unp1)

suite(662522)
```
But Ididn’t noticed that the source code is ramdomly generated !
So I need to take the source code Of the opened page . How can I do it using python?

But your code is also good btw.

Punkachu
9 years ago

0

Dloser
Sorry I’m french , sorry for my bad English , actually I try to do the following challenge :
http://www.root-me.org/en/Challenges/Programming/Arithmetic-progression-18

PNTSTR
9 years ago

1

Seems like that challenge similar to https://www.hackthis.co.uk/levels/coding/1
As you are here now, try to solve this chalenge first.

dloser
9 years ago

0

@Punkachu**: Perhaps try to read the documention of the modules you are using?

Punkachu
9 years ago

0

You are both right x )
I’ve already done those but it seems I ’ve made something wrong.
I can code harder things I guess x ) don’t want to waste my time on it x )
And yes the 2 imports which will be useful here are : webbrowser and urllib2 , I will check them out , I already found a way.

Thank you guys !

I will shut the thread now ; ]

PNTSTR
9 years ago

0

Perhaps one of the best material on the subject: Using Python to Access Web Data on Coursera
https://www.coursera.org/learn/python-network-data/lecture/TdznM/understanding-html

Punkachu
9 years ago

0

Wow Very interessting !
Thank you man !

Punkachu
9 years ago

0

I actually succeed to do it.

But I need to handle cookies sessoin now ahah and then I will succeed it !

DOSmaster
9 years ago

0

Read up on how cookies are sent. :)
Shouldn’t be too hard, I am sure.

Punkachu
9 years ago

0

I cant cougth them but I don’t know what should I do next . T , T
Once I load it I need to set it up instead of the previous one to keep the webpage the same ?

dloser
9 years ago

1

Read up on cookies. Read documentation. Use the proper modules (like ‘requests’). Write proper posts that people can understand.

tehron
9 years ago

0

Aren’t cookies supposed to be in a cookie jar? And do we need Java for that??

Punkachu
9 years ago

0

Okay I will make a new thread now x)
Thanks again all.

Discussion thread has been locked. You can no longer add new posts.
1 of 18

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss