我正在尝试提交表单并检索一些数据 使用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']
答案 0 :(得分:1)
检查错误发生在哪一行,可能是任何变量originairport_field
,destinationairport_field
,odate_field
,rdate_field
,adults_field
都没有分配
顺便提一下,您设置session
和rdate_field
值的行中的adults_field
来自哪里?不是sess
修改强>
根据您更新的错误信息,sess.at_xpath('.//*[@id="acOriginAirport"]')
可能无法返回任何内容。