网络自动化 - 自动检查链接

发布于 2024-09-26 18:46:33 字数 155 浏览 4 评论 0原文

我是网络应用程序的新手,我想检查何时有新版本的 Dota 地图,我会检查 getdota.com 中的链接。 我该如何做到这一点以及哪种语言,我希望它在每次启动魔兽争霸时进行检查,并自动将新地图下载到特定文件夹。 我的问题是:您能否提供有关网络自动化或类似内容的特定文章的链接。 先谢谢了:)

I'm new to web app and I want to check when there's a new version of dota map, I'll check links in getdota.com.
How can I do this and which language, I want it checks every time you start warcraft, and auto download new map to specific folder.
My question is : Can you give a link to a specific article about web automation or something like that.
Thanks first :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭水袖舞倾城 2024-10-03 18:46:34

以下是 Python 中的示例。

它解析getdota.com页面,读取下载地图的POST请求的参数,获取文件并将其保存在配置的目录中(默认为当前目录)。

#!/usr/bin/env python
import urllib
import urllib2
import sgmllib
from pprint import pprint
import os.path
import sys

url = 'http://www.getdota.com/'
download_url = 'http://www.getdota.com/app/getmap/'
chunk = 10000
directory = '' #directory where file should be saved, if empty uses current dir

class DotaParser(sgmllib.SGMLParser):
    def parse(self, s):
        self.feed(s)
        self.close()
    def __init__(self, verbose=0):
        sgmllib.SGMLParser.__init__(self, verbose)
        self.URL = ''
        self.post_args = {}
    def getArgs(self):
        return self.post_args
    def start_input(self, attributes):
        d = dict(attributes)
        if d.get('id', None) == None:
            return
        if d['id'] in ["input_mirror2", "input_file_name2", "input_map_id2", "input_language2", "input_language_id2"]:
            self.post_args[d['name']] = d['value']

if __name__ == '__main__':
    dotap = DotaParser()
    data = urllib2.urlopen(urllib2.Request('http://www.getdota.com/')).read()
    dotap.parse(data)
    data = urllib.urlencode(dotap.getArgs())
    request = urllib2.Request(download_url, data)
    response = urllib2.urlopen(request)
    page = response.read()

    #download file
    fname = directory + page.split('/')[-1]
    if os.path.isfile(fname):
        print "No newer file available"
        sys.exit(0)
    f = open(fname, 'w')
    print "New file available. Saving in: %s" % fname
    webFile = urllib.urlopen(page)
    c = webFile.read(chunk)
    while(c):
        f.write(c)
        c = webFile.read(chunk)
    f.close()
    webFile.close()

Below is an example in Python.

It parses getdota.com page, reads parameters for POST request for downloading a map, gets the file and saves it in configured directory (by default current directory).

#!/usr/bin/env python
import urllib
import urllib2
import sgmllib
from pprint import pprint
import os.path
import sys

url = 'http://www.getdota.com/'
download_url = 'http://www.getdota.com/app/getmap/'
chunk = 10000
directory = '' #directory where file should be saved, if empty uses current dir

class DotaParser(sgmllib.SGMLParser):
    def parse(self, s):
        self.feed(s)
        self.close()
    def __init__(self, verbose=0):
        sgmllib.SGMLParser.__init__(self, verbose)
        self.URL = ''
        self.post_args = {}
    def getArgs(self):
        return self.post_args
    def start_input(self, attributes):
        d = dict(attributes)
        if d.get('id', None) == None:
            return
        if d['id'] in ["input_mirror2", "input_file_name2", "input_map_id2", "input_language2", "input_language_id2"]:
            self.post_args[d['name']] = d['value']

if __name__ == '__main__':
    dotap = DotaParser()
    data = urllib2.urlopen(urllib2.Request('http://www.getdota.com/')).read()
    dotap.parse(data)
    data = urllib.urlencode(dotap.getArgs())
    request = urllib2.Request(download_url, data)
    response = urllib2.urlopen(request)
    page = response.read()

    #download file
    fname = directory + page.split('/')[-1]
    if os.path.isfile(fname):
        print "No newer file available"
        sys.exit(0)
    f = open(fname, 'w')
    print "New file available. Saving in: %s" % fname
    webFile = urllib.urlopen(page)
    c = webFile.read(chunk)
    while(c):
        f.write(c)
        c = webFile.read(chunk)
    f.close()
    webFile.close()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文