首页 > 其他 > 详细

顺手摸来的beautifulsoup

时间:2017-03-14 00:31:23      阅读:253      评论:0      收藏:0      [点我收藏+]

使用github很卡,查找解决方法的时候发现一只野生神牛

http://www.cnblogs.com/weidiao/p/6376420.html

简述一下github访问加速的方法:修改本机hosts文件,绕过dns地址解析

但是网站ip 可能改变。如网上很多旧的host文件修改方法已经不能使用

神牛使用爬虫动态爬取ip地址,从而解决了复杂的手动查询问题

import requests
from bs4 import BeautifulSoup

for i in open("haha.txt"):  #haha.txt   包含github各域名
    url = "http://ip.chinaz.com/" + i.strip()    #.strip()可以去除多余的空格,回车
    resp = requests.get(url)            
 #requests.get(url) 经典爬取手段
    soup=BeautifulSoup(resp.text) 
#beautiful网页处理非常强大的包
#http://www.crummy.com/software/BeautifulSoup/
#http://cuiqingcai.com/1319.html
    x=soup.find(class_="IcpMain02")
    x=x.find_all("span",class_="Whwtdhalf")
    print(x[5].string.strip(),i.strip())

于是顺手配好了本机的hosts,还顺便学习了beautiful中的搜索文档树,啊顺便爬一发贴吧吧

import requests
from bs4 import BeautifulSoup
# -*- coding: UTF-8 -*-



for i in open("haha.txt"): #haha里放帖子编号
    url = "https://tieba.baidu.com/p/" + i.strip()
    resp = requests.get(url)
    soup=BeautifulSoup(resp.text)
    x=soup.find(class_="wrap2")
    x=x.find_all("span",class_="red")
    print (x[0].string.strip()) #抓取楼层帖子回复数
    print(x[1].string.strip())  #抓取楼层数

 

顺手摸来的beautifulsoup

原文:http://www.cnblogs.com/bitch1319453/p/6536736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!