Python之抓取网页元素
来源:互联网 发布:仓库出入库软件 编辑:程序博客网 时间:2024/05/22 00:28
import urllib.requestfrom bs4 import BeautifulSoupurl = "http://www.wal-martchina.com/walmart/store/14_hubei.htm"user_agent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"request = urllib.request.Request(url)request.add_header("User-Agent", user_agent)content = urllib.request.urlopen(request)soup = BeautifulSoup(content,from_encoding="gb18030")#店名shopname = soup.find_all('td', {"class": "xl714445"})#地址addresss = soup.find_all('td', {"class": "xl684445"})#联系电话phones = soup.find_all('td', {"class": "xl744445"})for shop in shopname: print("店铺名称:"+shop.text.lstrip().rstrip())print("----------------------------------------------")for address in addresss: print("店铺地址:"+address.text.lstrip().rstrip())sum = 0for phone in phones: if sum % 2 == 0: print("联系电话:" + phone.text.lstrip().rstrip()) else: print("交通路线:" + phone.text.lstrip().rstrip()) print('---------------------------------------------------') sum += 1
阅读全文
0 0
- Python之抓取网页元素
- Python之抓取动态网页
- Python网页抓取之Lxml
- Python学习之网页抓取(一)
- Python学习之网页抓取(二)
- python爬虫实践之网页抓取
- Python网页抓取之Beautiful Soup
- python项目之 抓取动态网页 抓取路由器客户
- 使用python抓取网页
- Python抓取中文网页
- python抓取网页图片
- Python抓取中文网页
- Python抓取中文网页
- python 抓取网页代码
- [Python]网页信息抓取
- Python抓取网页
- Python抓取网页链接
- python抓取网页
- java操作mysql的JDBC
- 微信JS_SDK使用和配置
- MatConvnet工具箱使用手册翻译理解一
- 数据预处理与特征选择
- Openstack+Ceph安装与配置(收集整理笔记)
- Python之抓取网页元素
- 大牛博客收集录
- 快速排序算法
- 面向对象设计原则之三--依赖倒置(转)原则
- highcharts统计图在IE8下不显示
- 找出以abc为前缀、中缀、后缀的词
- poj3267 The Cow Lexicon (dp)
- 【剑指offer-解题系列(47)】孩子们的游戏(圆圈中最后剩下的数)
- Codeforces 814C-An impassioned circulation of affection