我想写一个功能,需要一个网页的URL,下载网页,并返回该网页的URL列表(使用urllib模块) 任何帮助,将不胜感激从网页提取所有链接
-3
A
回答
5
在这里你去:
import sys
import urllib2
import lxml.html
try:
url = sys.argv[1]
except IndexError:
print "Specify a url to scrape"
sys.exit(1)
if not url.startswith("http://"):
print "Please include the http:// at the beginning of the url"
sys.exit(1)
html = urllib2.urlopen(url).read()
etree = lxml.html.fromstring(html)
for href in etree.xpath("//a/@href"):
print href
C:\Programming>getlinks.py http://example.com / /domains/ /numbers/ /protocols/ /about/ /go/rfc2606 /about/ /about/presentations/ /about/performance/ /reports/ /domains/ /domains/root/ /domains/int/ /domains/arpa/ /domains/idn-tables/ /protocols/ /numbers/ /abuse/ http://www.icann.org/ mailto:[email protected]?subject=General%20website%20feedback
相关问题
- 1. 从cefsharp上的网页提取链接
- 2. 提取所有从网页[R]
- 3. 从页面抓取所有链接
- 4. Jsoup从页面获取所有链接
- 5. 从Python页面中提取所有链接
- 6. 从Web页面(Web爬虫)中提取所有链接
- 7. Python和硒 - 从网页获取所有链接
- 8. 从无限大的网页获取所有文章链接?
- 9. 从HTML页面提取所有链接,排除特定表格中的链接
- 10. 我试图从一个网站提取所有链接,但只有一些链接被提取为什么?
- 11. 显示网页上的所有链接
- 12. jquery DomWindow网页上的所有链接
- 13. 无法点击从网页提取的特定区域提取的所有链接
- 14. 从网站中提取链接
- 15. 从网站链接中提取
- 16. 无法找到BeautifulSoup的所有链接,以从网站中提取链接(链接标识)
- 17. sed从html页面提取链接
- 18. 如何从HTML页面提取链接?
- 19. 如何从网站获取所有网站链接?
- 20. 如何以纯文本的形式提取网页上的所有URL(链接)?
- 21. 获取页面上的所有链接
- 22. [JAVA]从网页获取HTML链接
- 23. Python无法从网页获取链接
- 24. 从python网页获取链接
- 25. 从网页获取所有HTTP网址
- 26. 如何使用crawler4j提取页面上的所有链接?
- 27. 我正在尝试从网站获取所有链接,并在所有链接上单击一个链接
- 28. 使用Go lang从网页中提取链接
- 29. 自动从网页中提取供稿链接(原子,rss等)
- 30. 如何查找并从网页中提取链接?
你有什么这么远吗?你有什么具体问题? – Mat 2011-05-01 11:15:29
这个问题有多差? – 2011-05-01 11:19:08
我们不会为你做你的功课。 – 2011-05-01 11:29:17