zoukankan      html  css  js  c++  java
  • 顺手摸来的beautifulsoup

    使用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())  #抓取楼层数
    
  • 相关阅读:
    javascript中replace()
    防止IE6出现BUG的十种常见解决方法
    IE6 重复字符的bug
    IE6 BUG大全
    display:inline
    JavaScript 图片上传预览效果
    用一行代码让w3wp进程崩溃,如何查找w3wp进程崩溃的原因
    近期学习任务
    气死我的存储过程和用户定义函数
    Damn,China Mobile!!!!
  • 原文地址:https://www.cnblogs.com/bitch1319453/p/6536736.html
Copyright © 2011-2022 走看看