knothirsty
knothirsty

Reputation: 103

Dryscrape Form & Scraping Issue

I am trying to submit a form and retrieve some data with dryscrape but when I execute the program, I get the error:

Traceback (most recent call last):
   File "easyjettest.py", line 22, in <module>
     originairport_field.set(originairport)
AttributeError: 'NoneType' object has no attribute 'set'

I really can't figure out what is the problem. I've read the documentation and searched as much as I could online.

The code is the following:

import dryscrape
import sys

if 'linux' in sys.platform:
   # start xvfb in case no X is running. Make sure xvfb 
   # is installed, otherwise this won't work!
   dryscrape.start_xvfb()

originairport = 'Cyprus (Larnaca) LCA'
destinationairport = 'London Gatwick LGW'
odate = '16/08/2016'
adate = '18/08/2016'
adults = '1'

sess = dryscrape.Session(base_url = 'http://www.easyjet.com/en/')

sess.set_attribute('auto_load_images', False)

sess.visit('/')

originairport_field = sess.at_xpath('.//*[@id="acOriginAirport"]')
originairport_field.set(originairport)
destinationairport_field = sess.at_xpath('.//*           [@id="acDestinationAirport"]')
destinationairport_field.set(destinationairport)
odate_field = sess.at_xpath('.//*[@id="oDate"]')
odate_field.set(odate) 
rdate_field = session.at_xpath('.//*[@id="rDate"]')
rdate_field.set(rdate)
adults_field = session.at_xpath('.//*[@id="numberOfAdults"]')
adults_field.set(adults) 
originairport_field.form().submit()

# extract all links
for link in session.xpath('//a[@href]'):
  print link['href']

Upvotes: 1

Views: 731

Answers (1)

hellozee
hellozee

Reputation: 205

Check in which line the error is taking place ,probably any of the variables originairport_field, destinationairport_field, odate_field ,rdate_field,adults_field is assigned none.

By the way from where does the session in the lines where you set the values of rdate_field and adults_field come from? isnt that sess

Edit:

From your updated error info probably sess.at_xpath('.//*[@id="acOriginAirport"]') isnt returning anything.

Upvotes: 1

Related Questions