Feb-05-2018, 10:54 AM
Hi
I want to login on this website
https://www.cpcdi.pt/Account/Login
I have the credentials and I try the following code:
I got no error on this code but I'm not sure that it's work.
I need to download pictures from the address like
URL='https://www.cpcdi.pt/Produtos/Referencia?referencia=8745B006AA'
for that I try the code:
But no luck. I got
Thank you
I want to login on this website
https://www.cpcdi.pt/Account/Login
I have the credentials and I try the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import requests import sys import urllib.request import re def main(): # Start a session so we can have persistant cookies #session = requests.session(config={'verbose': sys.stderr}) # This is the form data that the page sends when logging in login_data = { 'CodCliente' : 'mycode' , 'UserName' : 'myuser' , 'Password' : 'mypass' , 'submit' : 'submit' , } # Authenticate r = session.post(URL, data = login_data) # Try accessing a page that requires you to be logged in r = session.get(URL) |
I need to download pictures from the address like
URL='https://www.cpcdi.pt/Produtos/Referencia?referencia=8745B006AA'
for that I try the code:
1 2 3 4 5 6 7 8 9 10 11 12 |
req = urllib.request.Request(URL, headers = { 'User-Agent' : 'Mozilla/5.0' }) htmltext = urllib.request.urlopen(req).read() if htmltext is None : print ( "nada" ) else : regex = '<img src="/(.+?)"' pattern = re. compile (regex) imagem = pattern.findall( str (htmltext)) print (imagem[ 0 ]) #descarrega imagem import urllib.request urllib.request.urlretrieve(URL + imagem[ 0 ], "local-filename.jpg" ) |
Error:Traceback (most recent call last):
File "C:\python-ficheiros\abrir.py", line 33, in <module>
print(imagem[0])
IndexError: list index out of range
Any help on this matter?Thank you