erwewwewe 发表于 2017-3-16 14:33:24

python beautifulsoup bs4爬虫 爬取糗事百科

    声明:仅用于学习语法,请勿用于非法用途


    import urllib.request

    import re

    from bs4 import BeautifulSoup

    # -*- coding:utf-8 -*-


    url = 'http://www.qiushibaike.com/hot/'

    user_agent='Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'

    headers={'User-Agent':user_agent}

    request = urllib.request.Request(url=url,headers=headers)

    response = urllib.request.urlopen(request)

    bsobj = BeautifulSoup(response.read(), "html5lib")

    #content = response.read().decode('utf-8')

    #print(bsobj)

    nameList = bsobj.find_all("div", {"class":"content"})

    for name in nameList:

      print(name.get_text())

      input_enter = str(input())

      if input_enter =='':

            continue
页: [1]
查看完整版本: python beautifulsoup bs4爬虫 爬取糗事百科