使用python抓取有道词典的网页并返回结果信息

使用Python写了一个抓取有道词典首页的脚本,目前功能还不完善,只能抓取基本的Tag并使用BeautifulSoup显示出来,没有对Tag里的信息进行细分。另外,网页端是按utf-8编码的,放到Windows上的命令行里无法正常显示,目前还没有测试Linux终端里的情况。有时间再完善一下吧。




#! /usr/bin/python
# coding = utf-8

# youdao.py
# To-do: get meaning of a word from youdao.com
# Author: Steven
# Date: 2013/04/21

import urllib, urllib2
from bs4 import BeautifulSoup
import sys

inputDecode = sys.stdin.encoding
outputDecode = sys.stdout.encoding


def getHtml(word = 'bless'):
	#word = raw_input("Please input your word:")
	youdaoHtml = 'http://dict.youdao.com/search'
	youdaoData = {'le': 'eng', 'q': word, 'keyfrom': 'dict'}
	youdaoRequest = urllib2.Request(youdaoHtml, urllib.urlencode(youdaoData))
	youdaoRequest.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 8.0; Wind
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值