Changing communication in python mechanics

I am trying to write a python script that will generate my batch ranking. To do this, I just need to change the number of link rolls parameter using the check item function in a web browser. The link (relative) looks something like this:

/academic/utility/AcademicRecord.jsp?loginCode=000&loginnumber=000&loginName=name&Home=ascwebsite

I just need to change my loginCode to get an estimate of my partners. I am trying to use python to repeat all roll numbers and create a list of ranks. I used a mechanized library to open a site using python. Relevant piece of code:

br = mechanize.Browser()
br.set_handle_robots(False)
response = br.open('link_to_the_page')

Then I will do the necessary authentication and go to the corresponding page on which there is a link to view the ratings.
Then I find the appropriate link as follows:

for link in br.links(url_regex='/academic/utility/AcademicRecord.jsp?'):

URL . , :

response=br.follow_link(link)
print response.read()

. , . URL , http://www.google.com.

link.url='http://www.google.com'
link.base_url='http://www.google.com'

- , google. .

+1
1

, follow_link() click_link() link absolute_url, . url base_url.

absolute_url :

BASE_URL = 'link_to_the_page'
for link in br.links(url_regex='/academic/utility/AcademicRecord.jsp?'):
    modified_link = ...
    link.absolute_url = mechanize.urljoin(BASE_URL, modified_link)
    br.follow_link(link)

, .

+2

Source: https://habr.com/ru/post/1540706/


All Articles