这里有一个网站,都是短连接的
http://dwz.wailian.work/
下面是python 的代码
import itchat
import requests
import json
from lxml import etree
@itchat.msg_register(itchat.content.TEXT,isGroupChat=True)
def text_reply(msg):
#print(msg.fromUserName)
#msg.user.send('你搜索的内容是:'+msg.text)
#msg.user.send('http://www.baidu.com')
#print(msg.toUserName)
print(msg.text[0:2])
if msg.text[0:2]=='搜索':
payload = {'wd': msg.text[2:], 'submit': ''}
r = requests.get('http://www.aifengys.com/index.php?m=vod-search',params=payload)
print(r.text)
selector=etree.HTML(r.text)
content=selector.xpath('/html/body/div[4]/div[3]/ul/li') #返回为一列表
print(len(content))
strx=''
if(len(content)==0):
strx=strx+'搜索的内容找不到啊!'
for index in range(len(content)):
strx = strx+str(index+1)+':'
strx =strx+selector.xpath('//a/span[2]/p[1]/text()')[index]+"\r\n"
#strx =strx+selector.xpath('//a/span[2]/p[2]/text()')[index]+"\r\n"
strx =strx+selector.xpath('//a/span[2]/p[3]/text()')[index]+"\r\n"
#print(selector.xpath('//a/p[0]/text()')[index])
#strx =strx+selector.xpath('//a/p/i/text()')[index]+"\r\n" #1080p
strx =strx+selector.xpath('//a/span[2]/p[4]/text()')[index]+"\r\n"
temp_href = "http://noval.gpzy88.com"+selector.xpath('/html/body/div[4]/div[3]/ul/li/a/@href')[index]
my_href = "http://www.gpzy88.com/myjump.php?url="+temp_href
r1 = requests.get('http://api.weibo.com/2/short_url/shorten.json?source=2849184197&url_long='+my_href)
json_html=json.loads(r1.text)#str转成字典,方便索引
list_html=json_html['urls']#信息位第一个列
dic_html=list_html[0]['url_short'] #字典格式存储
strx =strx+dic_html+'\r\n'
if(index==5):
break
#增加额外信息
if(len(content)==0):
strx=strx+'搜索的内容找不到啊!'
else
strx=strx+'搜索的内容找不到啊!'
msg.user.send(strx)
#/html/body/div[4]/div[3]/ul/li[1]/a/p/i
itchat.auto_login()
itchat.run()