免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1464 | 回复: 0
打印 上一主题 下一主题

python使用beautifulsoup问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-09 18:25 |只看该作者 |倒序浏览
  这里是代码
  1. import sys
  2. import urllib
  3. from urllib import request
  4. import os
  5. from bs4 import BeautifulSoup

  6. class DramaItem:
  7.     def __init__(self, num, title, url):
  8.         self.num = num
  9.         self.title = title
  10.         self.url = url
  11.     def __str__(self):
  12.         return self.num + '    ' + self.title
  13.     def openDrama(self):
  14.         os.startfile(self.url)
  15. response = urllib.request.urlopen('URL')
  16. html = response.read()
  17. soup = BeautifulSoup(html)
  18. dramaList = soup.findAll('div', attrs={'class':'list_block1 align_c'})
  19. dramaItems = []
  20. if(dramaList):
  21.     lis = dramaList[0].findAll('li')
  22.     for li in lis:
  23.         ps = li.findAll('p')
  24.         description = ps[1].text if len(ps)>1 else ''
  25.         num = ps[0].find('a').text
  26.         url = ps[0].find('a')['href']
  27.         di = DramaItem(num, description, url)
  28.         dramaItems.append(di)
  29. for di in dramaItems:
  30.     print(di)
  31. diLen = len(dramaItems)
  32. userChoice = int(input('input number to watch the drama:'))
  33. if userChoice >= 1 and userChoice <=diLen:
  34.     dramaItems[userChoice-1].openDrama()
复制代码
里面的dramaList = soup.findAll('div', attrs={'class':'list_block1 align_c'})中
attrs={'class':'list_block1 align_c'}这句怎么解释
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP