抓个网页玩玩

一不小心玩了58的网站,|×-×|
# /bin/bash

抓取网页文件,将下面url源码保存到当前路径下58.html文件中

curl -o 58.html  http://m.58.com/zz/zufang/?58ihm=m_house_index_zufang&58cid=342&PGTID=0d200001-0015-6158-e721-99a4cce37f6f&ClickID=2

获取指定部分的网页。通过sed命令取出<ul>``</ul>部分代码,存放到temp文件中

cat 58.html | sed -n  '/<ul class=\"list-info\"/, /<\/ul> /{//!p}' > 58.temp

截取其中含有“<a href” 字符串的行,

grep "<a href" 58.temp >58.temp1

通过正则取出url,存放到href_file中

grep -oP "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?" 58.temp1 > href_file

那么现在所有工作信息的url就已经抓取出来了,下一步好玩的,等我在做!

再更新一个版本的抓取网页

看脚本:
# /bin/bash
$keyword;

echo 抓取网页!
rm -f href_file
rm -f href_file.temp
rm -f 5858.temp
rm -f 5858.html
#在58兼职分类下,搜索关键字,关键字是传入的汉字的转译字符
curl -o 58.html -A "Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" http://m.58.com/zz/jianzhi/?key=$1
echo 截取所有的超链接,通过grep匹配正则表达式
cat 58.html | grep -oP "(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?" | uniq  > href_file
echo 抓取符合规范的url
cat href_file | grep -o "http://.*.shtml.*" >> href_file.temp
cat href_file | grep -o "http://jump.*" >> href_file.temp
cat href_file | grep -o "http://.*.shtml" >> href_file.temp
echo 遍历url
cat href_file.temp | while read line
do
echo "url为" $line
curl -o 5858.html $line 
#输出公司名称
cat 5858.html | grep -o "m_detail_job_parttime_qyml.*.</a>" | grep -o ">.*.<" | grep -o "\w*" | uniq >> 5858.temp
#输出电话号码
cat 5858.html | grep -o "phoneno=\".*.\""|grep -o "\".*ton"|grep -oP '0\d{3}-\d{7}|1[3578]\d{9}' | uniq >> 5858.temp
done
cat 5858.temp

抓取出来的页面,会出现公司名称对应没有电话号,是因为这家公司隐藏了他们的电话,所有无法通过标签获取到电话号。能抓取出来的信息,都必须满足上文中的匹配

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容