Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1743204
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2015-09-20 09:09:03

从iciba.com 查询单词,脚本两个函数如下,

点击(此处)折叠或打开

  1. import requests
  2. from bs4 import BeautifulSoup
  3. from urllib.request import urlopen

  4. def query_words(words):
  5.     url=" style="color:#0000CC;">+str(words)
  6.     content=urlopen(url)
  7.     soup=BeautifulSoup(content.read(),'lxml')
  8.     answers=soup.find("span",{"class":"label_list"}).children
  9.     for i in answers:
  10.         print(i.string)

  11. def query_words_requests(words):
  12.     url=" style="color:#0000CC;">+str(words)
  13.     response=requests.get(url)
  14.     #print(response.text)
  15.     soup=BeautifulSoup(response.text,'lxml')
  16.     answers=soup.find("span",{"class":"label_list"}).children
  17.     for i in answers:
  18.         print(i.string)
另附beautiful的中文文档地址:
http://www.crummy.com/software/BeautifulSoup/bs3/documentation.zh.html

阅读(1240) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~