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 need to download pictures from the address like
URL='https://www.cpcdi.pt/Produtos/Referencia?referencia=8745B006AA'
for that I try the code:
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:
import requests
import sys
import urllib.request
import re
URL = 'https://www.cpcdi.pt/Account/Login'
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
URL='https://www.cpcdi.pt/Produtos/Referencia?referencia=8745B006AA'
r = session.get(URL)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:
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")But no luck. I got Error:Traceback (most recent call last):
File "C:\python-ficheiros\abrir.py", line 33, in <module>
print(imagem[0])
IndexError: list index out of rangeAny help on this matter?Thank you
