# 自行适配

### 通用规则

*   这里我做了NP架构站点的信息获取的通用XPATH

*   只要界面只是轻微改动的站点大部分能用，大家可以自行尝试一下，如果可以用，可以群里告诉我，我把站点加到支持列表

*   懂XPATH的大佬们可以参与一下，很简单的。

```python
# 用户等级
//table[@id="info_block"]//span/a[contains(@class,"_Name") and contains(@href,"userdetails.php?id=")]/@class
U2: //img[contains(@src,"user")]/@src
TTG: //td[contains(text(),"等级")]/following-sibling::td/text()
# 用户ID
//table[@id="info_block"]//span/a[contains(@class,"_Name") and contains(@href,"userdetails.php?id=")]/@href

ttg://h1/a[contains(@href,"userdetails.php?id=")]/@href

# 用户passkey
//td[contains(text(),"Passkey")]/following-sibling::td[1]/text()
//td[contains(text(),"密钥")]/following-sibling::td[1]/text()
//td[contains(text(),"密匙")]/following-sibling::td[1]/text()
观众：//td[contains(text(),"密钥")]/following-sibling::td[1]/span/text()
U2://td[contains(text(),"密钥")]/following-sibling::td[1]/span/@data-content
# 分享率
//font[@class="color_ratio"][1]/following-sibling::text()[1]

TTG: //font[contains(text(),"分享率 ")][1]/following-sibling::font[1]/text()[1]
U2：//span[contains(text(),"分享率")][1]/following-sibling::text()[1]
南洋、芒果：//img[@alt="Ratio"][1]/following-sibling::text()[1]

# 魔力值
//a[@href="mybonus.php"]/following-sibling::text()[1]
U2: //a[@href="ucoin.php"]/following-sibling::span[1]//text()
南洋、TTG: //a[contains(@href,"mybonus.php")]/text()[1]
joyhd：//a[@href="usebonus.php"]/following-sibling::text()[1]
# 时魔
//div[contains(text(),"每小时")]/text()[1]
mt：//td[contains(text(),"每小")]/text()[1]
U2: //td[@id="outer"]//td[@class="text"]/text()
TTG: //td[contains(text(),"总计")]/following-sibling::td/text()
# 做种积分
//font[@class="color_bonus" and contains(text(),"积分")]/following-sibling::text()[1]

TTG => HP: 
观众：//a[contains(@href,"blackjack.php")]/following-sibling::text()[1]

# 邀请
//span/a[contains(@href,"invite.php?id=")]/following-sibling::text()[1]

TTG: //a[contains(@href,"invite.php")]/span/text()[1]
南洋、芒果：//span/a[contains(@href,"invite.php")]/text()[1]

# 上传量
//font[@class="color_uploaded"]/following-sibling::text()[1]
TTG：//font[contains(text(),"上传量")]/following-sibling::font[1]/a/text()[1]
U2: //span[@class="color_uploaded"]/following-sibling::text()[1]
# 下载量
//font[@class="color_downloaded"]/following-sibling::text()[1]
U2: //span[@class="color_downloaded"]/following-sibling::text()[1]
TTG：//font[contains(text(),"下载量")]/following-sibling::font[1]/a/text()[1]
# 当前做种数
###  <img class="arrowup" alt="Torrents seeding" title="当前做种" src="pic/trans.gif">
//img[@class="arrowup"][1]/following-sibling::text()[1]
南洋：//img[@alt="Torrents seeding"][1]/following-sibling::text()[1]
TTG：//img[contains(@title,"做种中")]/following-sibling::font[1]/span/text()[1]
U2: .//a[contains(@href,"#seedlist")]//text()
# 当前下载数
//img[@class="arrowdown"][1]/following-sibling::text()[1]

南洋：//img[@alt="Torrents leeching"][1]/following-sibling::text()[1]
TTG：//img[contains(@title,"下载中")]/following-sibling::font[1]/span/text()[1]
# HR
//a[@href="myhr.php"]//text()

# 邮件
20220911更新
//a[@href="messages.php"]/font[contains(text(),"条")]/text()[1]

//a[@href="messages.php"]/font/text()[1]

TTG : //img[@alt="inbox"]/parent::a[contains(@href,"messages.php")]/following-sibling::text()[1]

# 注册日期
//td[contains(text(),"加入")]/following-sibling::td[1]//span/@title
U2://td[contains(text(),"加入")]/following-sibling::td[1]//time/@title
TTG： //td[contains(text(),"注册日期")]/following-sibling::td[1]/text()

# 最近活动日期
//td[contains(text(),"最近")]/following-sibling::td[1]//span/@title
U2: //td[contains(text(),"最近")]/following-sibling::td[1]//time/@title
TTG：//td[contains(text(),"上次访问")]/following-sibling::td[1]/text()

# 当前做种记录数、做种体积  pop(0)去除标题行，len获取记录数，获取的体积相加为做种体积
//tr/td[4]

U2/mt/joyhd：//tr/td[3]



# 种子表格
//table[@class="torrents"]/tr

# 种子名称 name_rule
.//td[@class="embedded"]/a/b//text()
ttg: .//div[@class="name_left"]/a/b/span/text()

# 种子标题
.//td[@class="embedded"]/a[contains(@href,"detail")]/following::text()[1]
ttg: .//div[@class="name_left"]/a/b/text()[1]
南洋：.//td[@class="embedded"]/a[contains(@href,"detail")]/parent::td/text()
joyhd:.//td[@class="embedded"]/a[contains(@href,"detail")]/following::text()[2]
# 详情页
.//td[@class="embedded"]/a[contains(@href,"detail")]/@href
ttg: .//div/a[contains(@href,"/t/")]/@href
# 分类
.//td[@class="rowfollow nowrap"][1]/a[1]/img/@title
.//td[@class="rowfollow nowrap"][1]/a[1]/img/@alt
.//td[@class="rowfollow nowrap"][1]/a[1]/img/@class
ttg: .//img[contains(@src,"cate")]/@alt
joyhd:.//td[@class="rowfollow nowrap"][1]/span/a[1]/img/@class
# 海报
无
# 首页行内下载链接 magnet 链接 magnet_url
.//a[contains(@href,"download.php?id=")]/@href
ttg: .//img[contains(@class,"dl_img")]/parent::a/@href
# 详情页下载链接
.//a[contains(@href,"download.php?") and contains(text(),"右键")]/@href
南洋：//a[contains(@href,"download.php?") and contains(text(),"右键")]/@href
月月：  .//input[@id="download_link"]/@value 
TTG：//a[contains(text(),"点击复制")]/@href
吐鲁番：.//a[contains(@href,"download.php?id=") and contains(@href,"passkey")]/@href

老师：.//a[contains(@href,"download.php?downhash=")]/@href

# 文件大小
.//td[5]/text()
# HR
无
# 促销
# .//div/img[contains(@class,"pro_")]/@alt
.//img[contains(@class,"pro_")]/@alt
ttg: .//img[contains(@src,"free")]/@alt
吐鲁番：  .//img[contains(@class,"pro_")]/@alt
# 或许可以为默认？
joyhd:.//img[contains(@class,"free")]/@alt
# 促销结束时间
# .//div/img[contains(@class,"pro_")]/@onmouseover
.//img[contains(@class,"pro_")]/following::font/span/@title
吐鲁番：.//img[contains(@class,"pro_")]/following::span[1]/@title

# 发布时间
.//td[4]/span/@title
南洋：.//td[4]/text()

# 做种人数
.//a[contains(@href,"#seeders")]/text()
.//a[contains(@href,"#seeders")]//text()
ttg: .//a[contains(@href,"&toseeders")]//text()
# 下载人数，无结果的为0
.//a[contains(@href,"#leechers")]/text()
.//a[contains(@href,"#leechers")]//text()
# 完成人数
.//a[contains(@href,"viewsnatches")]//text()
ttg: .//td[8]/text()[1]
# 平均完成进度
.//tr/td[9]/nobr/text()

吐鲁番：.//tr/td[8]/nobr/text()
# 平均下载速度
.//b[contains(text(),"下载者")]/parent::font/following-sibling::table/tr/td[6]/nobr/text()

# hash
//td[@class="no_border_wide"]/b[contains(text(),"Hash 码")]/following::text()[1]
//td/b[contains(text(),"Hash")]/following::text()[1]
```

### 使用教程

1.  登录站点，进入个人主页

2.  F12打开开发者工具，选择元素选项，在内容上点一下

    ![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662168732654-3ee9ee55-1ecb-4597-b373-b89a802beb35.png)

3.  ctrl+F或者command+F打开查找框

    ![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662168785057-dbdca513-6ab9-487b-8671-e72de472e876.png)

4.  把XPATH规则填入进去按回车，后面会显示当前找到了几条元素，如果是1/1，恭喜，规则可以用，如果是0就是没找到，有很多条就是有很多规则相同的元素，需要自行分析一下修改规则，上面示例中就是在种子详情页获取种子下载链接的Xpath（获取页面中的a链接的网址，指定a链接的网址中包含download.php和passkey字段）

> tips：

> xpath查找时，浏览器要识别tbody，代码中需要将tbody去掉

> /表示从根节点开始，//开始表示全文查找，./代表当前节点开始找，获取个人数据可以用//

## 自行测试

1.  打开PT站点管理 => 站点信息

2.  填入站点名称、站点网址（https\://\****.***/，一定要保留最后的斜杠）以及站点图标网址（可以直接填‘favicon.ico’）

![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662133970525-ef9a540e-9f34-4208-b076-98f46704b1b0.png)

1.  选择功能，签到、拉取个人数据、拉取首页种子与搜索（暂未开发），测试站点的话只需要勾选签到与拉取个人数据，因站点页面有差异，拉取种子基本不可用，但是可以尝试

![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662133982720-496bba5f-f912-4a3c-a34d-903f4757a19b.png)

1.  剩下的信息都有默认值，可以直接保存，当然如果你懂得XPATH，可以先自行在网站页面上使用通用规则测试一下。

## 添加站点

1.  打开 PT站点管理 => 我的站点

![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662134270604-8906ae05-7549-4e7c-bf97-2e7d294a3f4c.png)

1.  选择要添加的站点，按要求填入uid，passkey与cookie，其他保持默认保存即可

![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662134227249-123db103-953e-4f4a-a0f2-901866148ef0.png)

## 功能测试

1.  在我的站点页面，选中要测试的站点，点击签到或者更新数据或拉取种子（一次只能点一个，不然数据库会报错）

    ![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662134279472-4ead991a-b30a-41e2-8841-c9ab1884b4e3.png)

2.  成功的会有返回成功信息，错误的会在右上角的小弹窗里报错，我有时候会忘记关掉测试代码，可能会跳出一个黄色页面，类似于下面这个图片，里面直接指定了那一行有错，这个图片就是说程序在运行该文件第38行时出现了错误

    ![](https://cdn.nlark.com/yuque/0/2022/png/29662219/1662133785487-16603732-6178-4744-a9af-1c4a296b8902.png)

3.  无论成功或者失败，都可以在群里反馈给我，我会及时更新文档，以及对相应的站点进行支持。
