#!/bin/bash
curl_str='curl -x "http://http-pro.abuyun.com:9010" --proxy-basic --proxy-user H78H42TCN191075P:3D1EA6E4F458AB69'
curl_str='curl -L --socks5 socks-cla.abuyun.com:8030 --proxy-user S822RB9T27K96TPC:5E68523C79E62C41'
### encode url
encode_url(){
local supplier_name_encode="$(echo "$" | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g')"
echo "https://xin.baidu.com/s?q=${supplier_name_encode}&t=0"|perl -npe 's/\n//'
} do_down_web_info_html(){
local url=$(encode_url "$1")
local html_file="$2"
# wget ${url} -O ${html_file}
#echo -e "\n===================================> " ${curl_str} "${url}" \> ${html_file}"\n"
${curl_str} "${url}" > ${html_file}
} get_supplier_pid(){
local html_file="${1}.html"
local supplier_name="$2"
do_down_web_info_html "${supplier_name}" "${html_file}"
### 获取pid
echo $(grep compinfo ${html_file}|head -|awk -F'pid=' '{print $2}'|awk -F'"' '{print $1}')
} do_down_supplier_unifiedcode(){
local id="$1"
local pid="$2"
### 获取统一社会信用代码
local unifiedCode="${id}_unifiedCode"
local api_basic_url="https://xin.baidu.com/detail/basicAjax?pid=${pid}"
echo -e "\n 获取统一社会信用代码 ===================================> "${curl_str} "${api_basic_url}" \> ${unifiedCode}"\n"
${curl_str} "${api_basic_url}" > ${unifiedCode}
} do_switch_ip(){
# ${curl_str} http://proxy.abuyun.com/switch-ip
echo "do_switch_ip"
} do_run(){
local id="$1"
local supplier_name="$2"
pid=$(get_supplier_pid "${id}" "${supplier_name}")
do_down_supplier_unifiedcode "${id}" "${pid}"
# echo -n $(date "+%F %T")" | ${id} | ${supplier_name} | ${pid} |"
### 解析json为csv文件
# jq -r '[(.data.entName|tostring),(.data.unifiedCode|tostring)]|join("|")' "${id}_unifiedCode"
} result_file="result_code"
# "上海东福网络科技有限公司广州分公司","" token(){
local pid=$
# 判断是否有传入pid
if [ -z "${pid}" ]
then
echo "please input pid"
exit
fi # 设置并发数,默认为5
local concurrency=
if [ -n "$2" ]
then
concurrency=$
echo "Concurrency: $2"
fi # 创建有名管道,如果fd1不存在则创建
[ -e /tmp/fd1 ] || mkfifo /tmp/fd1
# 创建文件描述符,以可读(<)可写(>)的方式关联管道文件,这时候文件描述符999就有了有名管道文件的所有特性
# 为了让程序有一定的扩展性,不想写死fd,因而引入了变量。
# 因而引入eval命令,强制shell进行变量展开。
# eval exec "${fd}>file"简单的说,eval将右边参数整体作为一个命令,进行变量的替换,然后将替换后的输出结果给shell去执行。
eval exec "${pid}<>/tmp/fd1"
# 关联后的文件描述符拥有管道文件的所有特性,所以这时候管道文件可以删除,我们留下文件描述符来用就可以了
[ -e /tmp/fd1 ] && rm -f /tmp/fd1 # 初始化并行数
for ((i=;i<=${concurrency};i++))
do
# &999代表引用文件描述符999,这条命令代表往管道里面放入了一个"令牌"
echo ${i}>&${pid}
done
} main(){
local pid=$$
local start_time=`date +%s`
# 生成管道文件
token ${pid}
local num=
cat ../tmpa|head -|tail -|while read line
do
num=$((${num}+))
if [ ${num} -eq ]
then
do_switch_ip
num=
echo "==================================== reset num ===================================="
fi
# 获取令牌
read -u${pid} name
{
local supplier_info=($(echo ${line}|sed 's/"//g'|sed 's/,/ /'))
local id="${supplier_info[1]}"
local supplier_name="${supplier_info[0]}"
echo "${id} | ${supplier_name}"
do_run ${id} ${supplier_name}
# | tee -a ${result_file}_${name}
echo ${name}>&${pid}
} &
done wait
# 定义脚本运行的结束时间
local stop_time=`date +%s`
echo "TIME:`expr ${stop_time} - ${start_time}`"
# 关闭文件描述符的读
eval exec "${pid}<&-"
# 关闭文件描述符的写
eval exec "${pid}>&-"
} main

shell爬虫的更多相关文章

  1. Linux shell爬虫实现树洞网自动回复Robot

    奇怪的赞数 人生在世,不如意事十之八九,可与言者无二三人.幸好我们生在互联网时代,现实中找不到可以倾诉的人还可以在网络上寻找发情绪宣泄口,树洞这类产品就是提供一个让人在网络上匿名倾诉的平台. 我是偶然 ...

  2. shell爬虫--抓取某在线文档所有页面

    在线教程一般像流水线一样,页面有上一页下一页的按钮,因此,可以利用shell写一个爬虫读取下一页链接地址,配合wget将教程所有内容抓取. 以postgresql中文网为例.下面是实例代码 #!/bi ...

  3. shell爬虫简易脚本(线程数可控)

    1.介绍 以机电之家网站为例 经过初步分析,机电之家的数据量较大,并且数据组织规则较为统一,适合以代码方式进行全量爬取. 企业列表URL统一为http://www.jdzj.com/yp_vlist_ ...

  4. shell 爬虫 从日志分析到数据采集与分析

    [root@VM_61_158_centos ~]# curl http://ip.chinaz.com/220.112.233.179 |grep -e Whwtdhalf.*span.*span. ...

  5. shell及Python爬虫实例展示

    1.shell爬虫实例: [root@db01 ~]# vim pa.sh #!/bin/bash www_link=http://www.cnblogs.com/clsn/default.html? ...

  6. scrapy知识积累

    Scrapy 中文文档https://scrapy-chs.readthedocs.io/zh_CN/latest/intro/overview.html 创建项目 scrapy startproje ...

  7. SHELL网络爬虫实例剖析--转载

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://nolinux.blog.51cto.com/4824967/1552472 前天 ...

  8. 爬虫系列3:scrapy技术进阶(xpath、rules、shell等)

    本文主要介绍与scrapy应用紧密相关的关键技术,不求很深入,但求能够提取要点.内容包括: 1.xpath选择器:选择页面中想要的内容 2.rules规则:定义爬虫要爬取的域 3.scrapy she ...

  9. Python爬虫教程-33-scrapy shell 的使用

    本篇详细介绍 scrapy shell 的使用,也介绍了使用 xpath 进行精确查找 Python爬虫教程-33-scrapy shell 的使用 scrapy shell 的使用 条件:我们需要先 ...

随机推荐

  1. 前端插件--swiper.js

    使用swiper.js还要注意引入它的同时也要引入swiper.css样式文件: swiper官方文档:http://www.swiper.com.cn/api/effects/193.html 实例 ...

  2. 访问树中的所有元素(DOM)

    创建一个函数,给定页面上的DOM元素,将访问元素本身及其所有后代(而不仅仅是它的直接子代).对于访问的每个元素,函数应将该元素传递给提供的回调函数. 函数的参数应该是: 一个DOM元素 一个回调函数( ...

  3. 前端(jQuery)(5)-- jQuery AJAX异步访问和加载片段

    异步访问 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  4. hdu 2586 (lca-RMQ)

    #include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...

  5. 工控安全入门(一)—— Modbus协议

    modbus基础知识 modbus协议最初是由Modicon公司在1971年推出的全球第一款真正意义上用于工业现场的总线协议,最初是为了实现串行通信,运用在串口(如RS232.RS485等)传输上的, ...

  6. 零开始Android逆向教程(一)——初探Android逆向

    这段时间因为某些业务驱动,开始研究一些逆向相关的东西,浏览了下其所包含的大致内容,发现真是一个新大陆,跟之前耳听目染过的一些门面介绍完全不是一个层级的,真正的印证了下手难这一说法.   谨此以本文开始 ...

  7. Eclipse 出现select type (? = any character,*= any String,Tz=TimeZone)

    在eclipse中想运行project的时候,往往是右键项目名称---->run As --->Java Application 但是会弹出窗口显示select type (? = any ...

  8. gitlab上fork别人的代码后更新的2种解决方式

    1.解决方式1 首先要先确定一下是否建立了主repo的远程源: git remote -v如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源: git remote ...

  9. 关系数据库标准语言 SQL (ch.3)

    3.1 SQL 概述 3.1.2 特点 1 综合统一 非关系型语言 的数据语言都分为 DDL Scheme Data Definitin Language, 模式DDL SubScheme Data ...

  10. centos6.5 zabbix2.2 亲测安装

    因为需要做测试,调试.需要安装zabbix.  然后自己新弄了一个 centos6.5 minimal版本,从头来了一遍. 1.先安装LAMP的环境还有一些基本环境. yum -y install g ...