我经常阅读音乐网站,它有一个部分,用户可以发布自己的虚构音乐相关故事。有一个91部分系列(写在一段时间,部分上传),总是遵循以下约定: http://www.ultimate-guitar.com/columns/fiction/riot_band_blues_part_#.html。Python HTML - 通过属性获取元素
我希望能够从每个部分获得格式化的文本并将其放入一个html文件中。
方便地,有一个打印版本的链接,正确格式为我的目的。我所要做的就是编写一个脚本来下载所有的部分,然后将它们转储到文件中。不难。
不幸的是,印刷版的网址为: www.ultimate-guitar.com/print.php?what=article & ID = 95932
知道什么文章对应的唯一方法是什么ID字段是查看原始文章中某个输入标签的值属性。
我想要做的是这样的:
Go to each page, incrementng through the varying numbers.
Find the <input> tag with attribute 'name="rowid"' and get the number in it's 'value=' attribute.
Go to www.ultimate-guitar.com/print.php?what=article&id=<value>.
Append everything (minus <html><head> and <body> to a html file.
Rinse and repeat.
这可能吗? python是正确的语言吗?另外,我应该使用什么dom/html/xml库?
感谢您的任何帮助。
这将被视为跨域,并且不适用于浏览器安全目的 – Vigrond 2012-02-26 03:51:59
正确。它将作为一个修改一点点的油门猴脚本。 – beerbajay 2012-02-26 05:04:34