Forums

Getting response https://ahrefs.com/writing-tools/meta-description-generator

Hello people: I'm trying to get the correct response from: https://ahrefs.com/writing-tools/meta-description-generator

I am using this code:

  import mechanize

  urltarget = "https://ahrefs.com/writing-tools/meta-description-generator"        
  headers = {                                                                           
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.  0'}
  br = mechanize.Browser()                                                              
  br.set_handle_robots(False)                                                           
  br.set_header(headers)                                                                
  br.open('https://ahrefs.com/writing-tools/meta-description-generator')                
  response = br.submit()

  br.select_form(nr=0)

  br.form.controls[1].attrs['value'] = "Este como que si va a funcionea"

  mytext = ' This is a long text ' * 25

  br.form.controls[1].attrs['value'] = mytext                                           
  response = br.submit()                                                                
  response.read()                                                                       
  data = response.get_data()                                                            
  print(data)

But data not contain the correct or similar expected text (meta description)

Please help me to get the expected value. Thanks in advance

I bet if you were to check the response status code it'd be a 403 - https://help.pythonanywhere.com/pages/403ForbiddenError/