【脚本语言系列】关于PythonWeb服务自动化BeautifulSoup,你需要知道的事
2017-06-14 11:19
981 查看
如何使用BeautifulSoup
# -*- coding:utf-8 -*- import requests import sys from bs4 import BeautifulSoup as soup def get_links(url): result = requests.get(url) page = result.text doc = soup(page) links = [element.get("href") for element in doc.find_all("a")] return links if __name__ == "__main__": url = "http://www.baidu.com" for num, link in enumerate(get_links(url), start=1): print num, link print
1 http://news.baidu.com 2 http://www.hao123.com 3 http://map.baidu.com 4 http://v.baidu.com 5 http://tieba.baidu.com 6 http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 7 //www.baidu.com/more/ 8 http://home.baidu.com 9 http://ir.baidu.com 10 http://www.baidu.com/duty/ 11 http://jianyi.baidu.com/
相关文章推荐
- 【脚本语言系列】关于PythonWeb服务自动化REST,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化webbrowser模块,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化Web API,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器apache+mod_wsgi,你需要知道的事
- 【脚本语言系列】关于Python网页服务Microsoft IIS,你需要知道的事
- 【脚本语言系列】关于Python网页服务Zope, 你需要知道的事
- 【脚本语言系列】关于Python网页服务Plone,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Nginx+uWSGI,你需要知道的事
- 【脚本语言系列】关于Python邮件服务smtplib,你需要知道的事
- 【脚本语言系列】关于PythonWeb客户端-服务器模块http-urllib,你需要知道的事情
- 【脚本语言系列】关于PythonWeb客户端标准库requests,你需要知道的事情
- 【脚本语言系列】关于Python网页服务Apache,你需要知道的事
- 【脚本语言系列】关于Python邮件服务poplib,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Flask,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
- 【脚本语言系列】关于Python数值计算Pandas,你需要知道的事
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- 【脚本语言系列】关于Python统计分析statsmodel,你需要知道的事
- 【脚本语言系列】关于Python游戏工具Pygame,你需要知道的事