当前位置:   article > 正文

python-爬虫(今日新闻头条练手)_python刷阅读 头条

python刷阅读 头条

这里写图片描述

# coding=utf-8

from tkinter import *
import urllib.request

root = Tk()
root.title = "今日头条"
root.geometry("450x560")

can = Canvas(root,width=400,height=560,bg="orange")
can.pack()

url = "http://www.mnw.cn/news/top/"
data = urllib.request.urlopen(url).read().decode("UTF-8")
res = '<a\starget.*?>(.*?)</a>'
ress = '<a\starget.*?>\s*(.*?)\s*</a>'
resss = '<a.*?>(.*?)</a>'
res_two = '<p>\s*(.*?)\s*</p>'

result = re.findall(res, data)
results = re.findall(ress, data)
resultss = re.findall(resss, data)
result_two = re.findall(res_two, data)

k = 0
for i in result:
    print(i)
    k = k + 20
    can.create_text(200, k, text=i)
#for i in resultss:
    # print("bbbb")
    # print(i)


# for i in result_two:
    # print("aaaaaa")
can.mainloop()
# print(i)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/958729
推荐阅读
相关标签
  

闽ICP备14008679号