我有一个基本的循环来查找我用urllib2.urlopen检索的页面上的链接,但是我试图只跟踪页面上的内部链接。。在
有什么办法让我的下面的循环只得到在同一个域的链接吗?在
for tag in soupan.findAll('a', attrs={'href': re.compile("^http://")}):
webpage = urllib2.urlopen(tag['href']).read()
print 'Deep crawl ----> ' +str(tag['href'])
try:
code-to-look-for-some-data...
except Exception, e:
print e
给你的爬虫一些建议:将mechanize与BeautifulSoup结合使用,这将大大简化你的任务。在
如果主机相同或主机为空(表示相对路径),则url属于同一主机。在
^{pr2}$因为你这么做
不会使用相对路径。 他们就像
也许根本不用re?在
相关问题 更多 >
编程相关推荐