python爬虫torrentkitty的种子






python爬虫torrentkitty的种子


话不多说上源代码,只要把lxml的库安装下就好了

这个程序完全是解放双手,而且没有弹窗网页等困扰

__author__ = 'JianqingJiang'
# -*- coding: utf-8 -*-
import urllib2
from lxml import etree
import os
pre_url ='http://www.torrentkitty.org/search/tokyohot/'
os.chdir('/Users/JianqingJiang/Downloads/')

def steve(page_num,file_name):
    url = pre_url + str(page_num)
    print url
    ht = urllib2.urlopen(url).read()
    content = etree.HTML(ht.lower().decode('utf-8'))
    mags = content.xpath("//a[@rel='magnet']")
    with open(file_name,'a') as p: # '''Note''':Append mode, run only once!
        for mag in mags:
            p.write("%s \n \n"%(mag.attrib['href'])+"\n") ##!!encode here to utf-8 to avoid encoding
            print "%s \n \n"%(mag.attrib['href'])

for page_num in range(0,10):
    print (page_num)
    steve(page_num, 'steve.txt')

差不多爬了10页就这样了。。。。


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,我们需要安装Python的一些库来实现爬取。其中,requests库是用来进行网络请求的,beautifulsoup4库是用来解析HTML文档的,lxml是beautifulsoup4的HTML解析器。 在爬取之前,需要先打开torrentkitty的网站,切换到高级搜索,然后输入要搜索的关键词。接着,我们需要在搜索结果页面的源代码中找到种子文件的下载链接。可以通过打开浏览器的开发者工具来查看网页的源代码。 然后,我们就可以使用requests库发送HTTP请求,获取搜索页面的内容。使用beautifulsoup4库将HTML文档解析为BeautifulSoup对象,使用soup.select()方法选择我们所需要的元素,也就是种子文件的下载链接。最后,我们可以使用Python的文件操作函数来下载种子文件。 以下是示例代码: ```python import requests from bs4 import BeautifulSoup url = 'https://www.torrentkitty.tv/search/keyword' keyword = 'your_keyword' # 使用requests库发送HTTP请求 res = requests.get(url + keyword) # 将HTTP响应的HTML文档解析为BeautifulSoup对象 soup = BeautifulSoup(res.text, 'lxml') # 获取种子文件的下载链接 links = soup.select('.download') # 可以通过浏览器的开发者工具获取CSS选择器 # 遍历下载链接,依次下载种子文件 for link in links: href = link['href'] filename = href.split('/')[-1] response = requests.get(href) with open(filename, 'wb') as f: f.write(response.content) ``` 以上代码只是简单示例,实际爬取过程中需要注意网站的反爬机制,并加入相应的代码处理。另外,请在爬取过程中注意遵循网站的相关规定,不要进行非法操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值