Search code examples
pythonurllib2

Urllib2 grab web-page element then reverse it


I need to visit http://www.chiquitooenterprise.com/ reverse the string and access the website using this URL: http://www.chiquitooenterprise.com/password?code=REVERSEDSTRING

How can i do this using urllib2 and Python?


link = "http://www.chiquitooenterprise.com/password"
request = urllib2.Request("http://www.chiquitooenterprise.com/password")
contents = urllib2.urlopen(request).read()

revString = request[::-1]
answer = "http://www.chiquitooenterprise.com/password?code=" + revString
response = urllib2.urlopen(answer)
response = response.read()
print(response)```

Solution

  • link = "http://www.chiquitooenterprise.com/password"
    result = requests.get("http://www.chiquitooenterprise.com/password")
    contents = result.text
    
    revString = contents[::-1]
    answer = f"http://www.chiquitooenterprise.com/password?code={revString}" 
    response = requests.get(answer)
    response = response.text
    print(response)