我正在尝试保存没有弹出框的csv文件。我按照以下链接找出了我的哑剧:
我甚至添加了mimeTypes.rdf文件中的所有NC_values。但是,它似乎没有起作用。
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'irc,ircs,webcal,application/csv,application/download,application/pdf')
mimeTypes.rdf
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Seq RDF:about="urn:schemes:root">
<RDF:li RDF:resource="urn:scheme:webcal"/>
<RDF:li RDF:resource="urn:scheme:ircs"/>
<RDF:li RDF:resource="urn:scheme:mailto"/>
<RDF:li RDF:resource="urn:scheme:irc"/>
</RDF:Seq>
<RDF:Description RDF:about="urn:scheme:mailto"
NC:value="mailto">
<NC:handlerProp RDF:resource="urn:scheme:handler:mailto"/>
</RDF:Description>
<RDF:Description RDF:about="urn:handler:web:https://30boxes.com/external/widget?refer=ff&url=%s"
NC:prettyName="30 Boxes"
NC:uriTemplate="https://30boxes.com/external/widget?refer=ff&url=%s" />
<RDF:Description RDF:about="urn:scheme:irc"
NC:value="irc">
<NC:handlerProp RDF:resource="urn:scheme:handler:irc"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:handler:mailto"
NC:useSystemDefault="true"
NC:alwaysAsk="false">
<NC:possibleApplication RDF:resource="urn:handler:web:https://compose.mail.yahoo.com/?To=%s"/>
<NC:possibleApplication RDF:resource="urn:handler:web:https://mail.google.com/mail/?extsrc=mailto&url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:handler:web:https://mail.google.com/mail/?extsrc=mailto&url=%s"
NC:prettyName="Gmail"
NC:uriTemplate="https://mail.google.com/mail/?extsrc=mailto&url=%s" />
<RDF:Description RDF:about="urn:scheme:handler:webcal"
NC:useSystemDefault="true"
NC:alwaysAsk="true">
<NC:possibleApplication RDF:resource="urn:handler:web:https://30boxes.com/external/widget?refer=ff&url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:application/pdf"
NC:value="application/pdf">
<NC:handlerProp RDF:resource="urn:mimetype:handler:application/pdf"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:ircs"
NC:value="ircs">
<NC:handlerProp RDF:resource="urn:scheme:handler:ircs"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:handler:ircs"
NC:alwaysAsk="true">
<NC:possibleApplication RDF:resource="urn:handler:web:https://www.mibbit.com/?url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:handler:application/download"
NC:alwaysAsk="true" />
<RDF:Description RDF:about="urn:mimetype:application/csv"
NC:value="application/csv"
NC:editable="true"
NC:fileExtensions="csv"
NC:description="Microsoft Excel Comma Separated Values File">
<NC:handlerProp RDF:resource="urn:mimetype:handler:application/csv"/>
</RDF:Description>
<RDF:Description RDF:about="urn:schemes">
<NC:Protocol-Schemes RDF:resource="urn:schemes:root"/>
</RDF:Description>
<RDF:Description RDF:about="urn:handler:web:https://compose.mail.yahoo.com/?To=%s"
NC:prettyName="Yahoo! Mail"
NC:uriTemplate="https://compose.mail.yahoo.com/?To=%s" />
<RDF:Description RDF:about="urn:handler:web:https://www.mibbit.com/?url=%s"
NC:prettyName="Mibbit"
NC:uriTemplate="https://www.mibbit.com/?url=%s" />
<RDF:Seq RDF:about="urn:mimetypes:root">
<RDF:li RDF:resource="urn:mimetype:application/pdf"/>
<RDF:li RDF:resource="urn:mimetype:application/download"/>
<RDF:li RDF:resource="urn:mimetype:application/csv"/>
</RDF:Seq>
<RDF:Description RDF:about="urn:scheme:handler:irc"
NC:alwaysAsk="true">
<NC:possibleApplication RDF:resource="urn:handler:web:https://www.mibbit.com/?url=%s"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:handler:application/csv"
NC:alwaysAsk="true" />
<RDF:Description RDF:about="urn:mimetypes">
<NC:MIME-types RDF:resource="urn:mimetypes:root"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:application/download"
NC:value="application/download"
NC:editable="true"
NC:fileExtensions="csv"
NC:description="Microsoft Excel Comma Separated Values File">
<NC:handlerProp RDF:resource="urn:mimetype:handler:application/download"/>
</RDF:Description>
<RDF:Description RDF:about="urn:scheme:webcal"
NC:value="webcal">
<NC:handlerProp RDF:resource="urn:scheme:handler:webcal"/>
</RDF:Description>
<RDF:Description RDF:about="urn:mimetype:handler:application/pdf"
NC:handleInternal="true"
NC:alwaysAsk="false" />
<RDF:Description RDF:about="urn:root"
NC:en-US_defaultHandlersVersion="4" />
</RDF:RDF>
我的完整代码:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/csv,application/download')
driver = webdriver.Firefox(profile)
driver.get(url)
time.sleep(5)
driver.switch_to.frame("main")
elem = driver.find_element_by_name('username')
elem.send_keys(username)
elem = driver.find_element_by_name("password")
elem.send_keys(password)
elem.send_keys(Keys.RETURN)
driver.find_element_by_xpath(".//*[@id='wrap']/div/div/div/div/div/div/div/div/div/div/div[2]/div/div/div/div[1]/div/span/span[2]/div[2]/table/tbody/tr/td[2]").click()
time.sleep(10)
driver.find_element_by_xpath(".//*[@id='scrollable']/div/div/div[1]/ul/li[1]/ul/li[2]/a[2]").click()
time.sleep(10)
#download report
try:
driver.switch_to.window(driver.window_handles[1])
element = WebDriverWait(driver,30).until(EC.presence_of_element_located((By.XPATH,".//*[@id='datablock']/div[5]/div[1]/div[10]/div[12]/input")))
driver.find_element_by_xpath(".//*[@id='datablock']/div[5]/div[1]/div[10]/div[12]/input").clear()
driver.find_element_by_xpath(".//*[@id='datablock']/div[5]/div[1]/div[10]/div[12]/input").send_keys(fromDate)
driver.find_element_by_xpath(".//*[@id='datablock']/div[5]/div[1]/div[10]/div[13]/input").clear()
driver.find_element_by_xpath(".//*[@id='datablock']/div[5]/div[1]/div[10]/div[13]/input").send_keys(toDate)
driver.find_element_by_xpath(".//*[@id='datablock']/div[1]/div[2]/a[2]").click()
driver.find_element_by_xpath("html/body/div[8]/ul/li/span").click()
driver.find_element_by_xpath(".//*[@id='datablock']/div[1]/div[2]/a[3]").click()
except:
print 'error'
答案 0 :(得分:3)
magic
Python模块说它是package object model {
type Mob = Actor with Indexable
object IndexableRepository {
def create[T <: Mob](capacity : Int) = Props(new IndexableRepository[T](capacity))
}
final class IndexableRepository[T <: Mob](val capacity : Int) extends Actor {
private var indexables = new Array[Mob](capacity)
def receive : Actor.Receive = {
case _ => unhandled()
}
private def findAvailable(indexables : Seq[Mob]) = {
(0 to indexables.size) find { idx => indexables(idx) == null }
}
}
}
:
text/plain
最终偏好(同时离开>>> import magic
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("report.csv")
'text/plain'
和application/csv
并添加application/download
和application/octet-stream
以确保安全):
text/csv