我已经创建了一个简单的ruby web scraper脚本,只是为了练习web scraping,该脚本在github中创建了一个仓库,然后应该在我的PC上创建目录->在此重定向我->进行初始提交->打开VSC。在ruby脚本完成之后,我不知道如何执行shell命令。 这是ruby脚本(是的,我知道我可以使用GithubAPI,但我想尝试网页抓取)
require 'rubygems'
require 'mechanize'
require 'dotenv'
Dotenv.load
def scraper
agent = Mechanize.new
agent.user_agent_alias = 'Mac Mozilla'
page = agent.get('https://github.com/login')
form = page.forms.first
form.field_with(name: 'login').value = ENV['GH_LOGIN']
form.field_with(name: 'password').value = ENV['GH_PASSWD']
page = form.submit
link = page.link_with(href: '/new')
page = link.click
form = page.forms[3]
form.field_with(name: 'repository[name]').value = ARGV[0]
form.radiobutton_with(name: 'repository[visibility]', value: 'private').click
page = form.submit
puts page.uri
end
scraper
这是我的zsh函数:
function create(){
cd
ruby create.rb $1
mkdir /Users/nmacuk/Documents/Projects/MyProjects/$1
cd /Users/myname/Documents/Projects/MyProjects/$1
git init
git remote add origin git@github.com:myname/$1.git
touch README.md
git add .
git commit -m "Initial Commit"
git push origin master
code .
echo "Repo named: $1 created succesfully in MyProjects/$1"
}
但是在我的ruby脚本之后,显然什么也没发生,只是结束了而已。有什么帮助吗?
尝试将exit
放在end
之前,但没有用