Python爬虫程序获取百度搜索结果的标题、描述、url。,python爬虫,使用BeautifulS
Python爬虫程序获取百度搜索结果的标题、描述、url。,python爬虫,使用BeautifulS
使用BeautifulSoup编写了一段爬虫程序。熟悉Java的jsoup包的话,对于Python的BeautifulSoup库应该很容易上手。
#coding: utf-8import sysimport urllibimport urllib2from BeautifulSoup import BeautifulSoupquestion_word = "吃货 程序员"url = "http://www.baidu.com/s?wd=" + urllib.quote(question_word.decode(sys.stdin.encoding).encode('gbk'))htmlpage = urllib2.urlopen(url).read()soup = BeautifulSoup(htmlpage)print len(soup.findAll("table", {"class": "result"}))for result_table in soup.findAll("table", {"class": "result"}): a_click = result_table.find("a") print "-----标题----\\n" + a_click.renderContents()#标题 print "----链接----\\n" + str(a_click.get("href"))#链接 print "----描述----\\n" + result_table.find("div", {"class": "c-abstract"}).renderContents()#描述 print#该片段来自于http://byrx.net
相关内容
- 比较两个文本的相似性,分词版。,相似性分词,比较两
- 百度图片下载,,#coding:utf-
- 翻番的力量,翻番力量,你要上帝一次性给你 1
- Python冒泡排序,python冒泡,# -*- coding
- 将目录中的TXT全成一个大TXT,目录TXTTXT,在网上下了一个
- window下调用api列出当前所有进程,windowapi列出当前,#!
- python 登陆 gfan打卡,pythongfan,学习python,搞了个
- 创建一个简单的电话本,支持添加和查询功能,创建查
- 在文本中,批量搜索信息,文本搜索信息,在C:\盘下面创
- darkBing SQL扫描器,darkbingsql扫描器,#!/usr/bin/p
评论关闭