我已经从webage(https://data.gov.in/catalog/variety-wise-daily-market-prices-data-cauliflower)下载了xml文件,其中我点击了超链接,这些超链接产生了一个表格,需要填写并提交以开始下载。我用selenium webdriver创建了代码。代码执行直到访问网页并单击xml超链接,但停止执行其余功能(单击电台和复选框,填写文本并单击提交按钮)以完成下载。如果我错过了我的代码中可能导致此问题的任何功能,请告诉我。任何建议/帮助将受到高度赞赏。谢谢。
import os
from selenium import webdriver
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "F:\Projects\Poli_Map\DatG_Py_Dat")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/xml")
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('https://data.gov.in/catalog/variety-wise-daily-market-prices-data-cauliflower')
driver.find_element_by_xpath('//*[@title="xml (Open in a new window)"]').click()
class FormPage(object):
def fill_form(self, data):
driver.find_element_by_xpath('//input[@type = "radio" and @value = "Non-commercial"]').click()
driver.find_element_by_xpath('//input[@type = "checkbox" and @value = "R&D"]').click()
driver.find_element_by_xpath('//input[@name = "name_d"]').send_keys(data['name_d'])
driver.find_element_by_xpath('//input[@name = "mail_d"]').send_keys(data['mail_d'])
return self
@staticmethod
def submit(self):
driver.find_element_by_xpath('//input[@type = "submit" and @value = "Submit"]').click()
data = {
'name_d': 'abc',
'mail_d': 'xyz@gmail.com',
}
FormPage().fill_form(data).submit(self)
driver.quit()