javascript - 谁能把这python个爬虫改成js版本的?
阿神
阿神 2017-04-11 10:21:53
[JavaScript讨论组]
import requests
from bs4 import BeautifulSoup
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

def yunpan_search(key):
    url='http://www.wangpansou.cn/s.php?q='+key
    html=requests.get(url)
    soup=BeautifulSoup(html.text,"lxml")
    url_get=soup.find_all('a',{'class':'cse-search-result_content_item_top_a'})
    info_get=soup.find_all('p',{'class':'cse-search-result_content_item_mid'})
    f = open('baidu_source.txt','w')
    for i in range(len(url_get)):
        href=url_get[i]['href']
        title=''
        for c in url_get[i].children:
            title+=c.string.strip()

        information=''
        for info in info_get[i].children:
            information+=info.string.strip().replace('\n','')

        print str(i+1)+'_'*60
        print '下载地址--'+href+'\n'+'链接标题--'+title+'\n'+'链接详情--'+information+'\n\n'
        f.write(str(i+1)+'. _____________________________________________________________________\n')
        f.write('下载地址--'+href+'\n'+'链接标题--'+title+'\n'+'链接详情--'+information+'\n\n')
    f.close()


if __name__=='__main__':
    key=raw_input('please input what you want to look for:')
    yunpan_search(key)
    print('finish')
阿神
阿神

闭关修行中......

全部回复(1)
怪我咯

简单看了下这个脚本:

应该是个盘搜应用,http://www.wangpansou.cn/s.php?q=关键词,请求url,获取查询结果,BeautifulSoup我记得是个处理html,xml的库。soup.find_all应该是用css选择器获取元素。那两个元素应该就是对应的搜索结果和链接了。

要实现的话不难,这个你应该自己可以做:

js的话,用node,找个requests,html(xml)解析的库就好了。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号