gpt4 book ai didi

python - python中的Ruby Mechanize 脚本

转载 作者:行者123 更新时间:2023-12-04 16:20:56 25 4
gpt4 key购买 nike

我有这个 ruby 脚本:

require 'mechanize'
agent = Mechanize.new
page = agent.get "http://www.speech.sri.com/projects/srilm/download.html"
form = page.forms.last
form.field_with(name: "name").value = "Hans Meier"
form.field_with(name: "org").value = "Meier AG"
form.field_with(name: "email").value = "hans.meier.org"
form.field_with(name: "address").value = "Baslerstrasse 32"
form.field_with(name: "file").value = "/project/srilm/srilm-1.6.0.tar.gz"
File.open('srilm.tgz') {|f| f.write agent.submit(form).body }

根据 intro page ,第一部分很简单,但是我不知道如何处理 form.field_with东西。

最佳答案

import mechanize
br = mechanize.Browser()
br.open("http://www.speech.sri.com/projects/srilm/download.html")
br.select_form(nr = True)
br['name'] = 'Hans Meier'
br['org'] = 'Meier AG'
br['email'] = 'hans.meier.org'
br['address'] = 'Baslerstrasse 32'
br['file'] = ['/project/srilm/srilm-1.6.0.tar.gz']
form_submission = br.submit()
with open('srilm.tgz', 'w') as f:
f.write(form_submission.read())

关于python - python中的Ruby Mechanize 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8552366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com