python抓取动态网页(:utf-8importurllib2fromBeautifulSoupimportBeautifulSoup;BeautifulSoup)

优采云 发布时间: 2022-01-14 08:14

  python抓取动态网页(:utf-8importurllib2fromBeautifulSoupimportBeautifulSoup;BeautifulSoup)

  #---------------------导入------------ ---------------#coding:utf-8import urllib2;from BeautifulSoup import BeautifulSoup;#--

  博客 Markdown 编辑器上线了! Wrox精品红皮电脑书PMBOK第五版,那些年我们一直在关注的,是火星敏捷开发1001题的视频教程

  Python实现网络爬虫爬取静态网页[代码]

  类别:蟒蛇

  #---------------------导入------------ ---------------#coding:utf-8import urllib2;from BeautifulSoup import BeautifulSoup;#--------- -------------------------------------------------- -------------------def main():#ץuserMainUrl = "?id=38b94c4ed8add8bcccabd7d31b22&fr=userbar"; #修改抓取的链接地址 req = urllib2.@ >Request(userMainUrl);resp = urllib2.@>urlopen(req);respHtml = resp.read();print "respHtml=",respHtml; #在这里输出所有捕获的HTML源代码#ȡsongtasteHtmlEncoding = "GBK";#修改编码字符集的格式soup = BeautifulSoup(respHtml, fromEncoding=songtasteHtmlEncoding);foundClassH1user = soup.find(attrs={"target":"_blank "});#修改抓取的内容 print "foundClassH1user=%s ",foundClassH1user;if(foundClassH1user):h1userStr = foundClassH1user.string;print "h1userStr=",h1userStr;############ ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# #if __name__=="__main__":main() ;

  获取 1 类标签

  #eg:siteUrls=soup.findAll('a')

  获取 2 个类标签

  #eg:foundClassH1user = soup.find(attrs={"target":"_blank"});

  获取 2 个类标签

  #foundClassH1user = soup.find(attrs={"class":"h1user"});

  上一篇文章在notepad++下搭建python编译器

  喜欢 1 不喜欢 0

  主题推荐猜你在找什么

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线