码迷,mamicode.com
首页 > 编程语言 > 详细

python抓取内涵段子文章

时间:2018-03-30 01:17:58      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:max   close   urllib   write   ==   item   www.   python   count   

# coding:utf-8
from urllib.request import urlretrieve
import threading
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import pymysql
import random
import  json
import  time

number=0
def GetArticel():
    max_time = 1519404642
    data = requests.get("http://www.neihanshequ.com/joke/?is_json=1&app_name=neihanshequ_web&max_time=" + str(max_time))
    soup = BeautifulSoup(data.text, ‘html5lib‘)
    #print(soup.select_one(‘body‘).get_text())

    global number
    jsondata=json.loads(str(soup.select_one(‘body‘).get_text()))
    articleList=jsondata[‘data‘][‘data‘]
    f = open("article.txt", ‘a‘,encoding=‘utf-8‘)
    for item in articleList:
       number+=1
       #print(number)

       f.write(item[‘group‘][‘content‘]+‘\n\n\n‘)
       print(number)
    f.close()



        # print(count)
        # print(item)


if __name__ == ‘__main__‘:

   for i in range(1,10):
    print(i)
    #GetArticel()
    #time.sleep(1)

  

python抓取内涵段子文章

标签:max   close   urllib   write   ==   item   www.   python   count   

原文地址:https://www.cnblogs.com/dongml/p/8673279.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!