Dryscrape Form&刮痧问题

时间:2016-08-16 16:00:32

标签: python web-scraping

我正在尝试提交表单并检索一些数据 使用dryscrape但是当我执行程序时,我收到错误:

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

我真的无法弄清问题是什么。我已经阅读了文档并尽可能多地在线搜索。

代码如下:

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']

1 个答案:

答案 0 :(得分:1)

检查错误发生在哪一行,可能是任何变量originairport_fielddestinationairport_fieldodate_fieldrdate_fieldadults_field都没有分配

顺便提一下,您设置sessionrdate_field值的行中的adults_field来自哪里?不是sess

修改

根据您更新的错误信息,sess.at_xpath('.//*[@id="acOriginAirport"]')可能无法返回任何内容。