Python.Following Links in HTML Using BeautifulSoup
来源:互联网 发布:c语言for语句 编辑:程序博客网 时间:2024/06/06 02:35
The program will use urllib to read the HTML from the data files below, extract the href= vaues from the anchor tags, scan for a tag that is in a particular position relative to the first name in the list, follow that link and repeat the process a number of times and report the last name you find.
Find the link at position 18 (the first name is 1). Follow that link. Repeat this process 7 times. The answer is the last name that you retrieve.
Hint: The first character of the name of the last page that you will load is: M
HTML地址:http://python-data.dr-chuck.net/known_by_Cleo.html
Python源码:
<span style="font-size:12px;">import urllibfrom bs4 import BeautifulSoupurl = raw_input('Enter - ')count = int(raw_input('Enter count:'))position = int(raw_input('Enter position:'))for tag in xrange(count):html = urllib.urlopen(url).read()soup = BeautifulSoup(html,'html.parser')tags = soup.findAll('a')url = tags[position-1].get('href', None)print url</span>
运行结果:
Enter - http://python-data.dr-chuck.net/known_by_Cleo.htmlEnter count:7Enter position:18http://python-data.dr-chuck.net/known_by_Mirrin.html
0 0
- Python.Following Links in HTML Using BeautifulSoup
- 【Python】 html解析BeautifulSoup
- python解析html之BeautifulSoup
- Python 用BeautifulSoup 解析Html
- Searching in baidu using BeautifulSoup in Python3.3
- Disable HTML a links in different browser
- 用python的BeautifulSoup分析html
- 用Python解析HTML,BeautifulSoup使用简介
- 用python的BeautifulSoup分析html
- [学习]用python的BeautifulSoup分析html
- python : BeautifulSoup 网页HTML 解析器
- [Python]BeautifulSoup—HTML解析包
- Python处理HTML利器——BeautifulSoup
- 用python的BeautifulSoup分析html
- 用python的BeautifulSoup分析html
- 学习]用python的BeautifulSoup分析html
- Python:[转]浅学BeautifulSoup分析html
- Python.Scraping HTML Data with BeautifulSoup
- JVM系列三:JVM参数设置、分析
- 百练 05 切割回文
- 欧拉定理——PowMod ( HDU 5728 )(2016 Multi-University Training Contest 1 1006)
- PHP基础语法之数组篇
- java设计模式-----单例模式
- Python.Following Links in HTML Using BeautifulSoup
- 总结 SAP ERP相关概念
- 定义一个类Demo,其中定义一个求两个数据和的方法,定义一个测试了Test,进行测试。
- java-计算两点之间的距离
- c语言_指针引用数组元素并打印输出
- Java内存区域---深入理解Java虚拟机
- Eclipse插件安装4种方法
- POJ-----1328
- 由两个栈组成的队列