1
我编写的程序从http://www.stevens.edu/中提取网页链接。 现在我遇到了以下与该程序有关的问题。搜索独特的网页链接
1 - 我想只有从链接http和https
2开始 - 我得到一个解析器BS4任何关于解析器缺乏规范的警示 - 解决
如何解决这个问题?我没有得到正确的方向来解决这个问题。
我的代码 -
import urllib2
from bs4 import BeautifulSoup as bs
url = raw_input('Please enter the url for which you want to see unique web links -')
print "\n"
URLs (mostly HTTP) in a complex world
req = urllib2.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
html = urllib2.urlopen(req).read()
soup = bs(html)
tags = soup('a')
count = 0
web_link = []
for tag in tags:
count = count + 1
store = tag.get('href', None)
web_link.append(store)
print "Total no. of extracted web links are",count,"\n"
print web_link
print "\n"
Unique_list = set(web_link)
Unique_list = list(Unique_list)
print "No. of the Unique web links after using set method", len(Unique_list),"\n"
请您澄清一下您的问题,您对“网站链接”和“本地内容”的定义看起来相当含糊。你的意思是你在寻找html文件而不是css,或者你的意思是你在寻找独特的域名?或者是其他东西? – OnGle
警告你可以有汤= bs(html,“lxml”)。对于获取唯一的网页链接,你可以有一个条件,如tag.get('href',None)中的'http': –
'如果'http'in tag.get('href',None):'仍然会得到样式表或任何由此事通过http服务虽然。 – OnGle