我在做一个爬虫项目。我陷入了这样一种情况:页面上的href文本在该域下的其他页面上不断重复。
例如,如果url是example.com网站然后这些页面上的href值是hrefList=[/hello/world,/aboutus,/blog,/contact]。在
所以这些网页的网址应该是
example.com/hello/world
example.com/aboutus
等等
现在在页面上example.com/hello/world,hrefList再次出现。因此,我将得到的网址
example.com/hello/world/hello/world,
example.com/hello/world/aboutus等等
现在在这些页面中/hello/world/hello/world是一个正确的页面,http状态为200,并且这是递归发生的。其余页面将找不到页面,因此可以丢弃
我得到的新网址列表不正确。有没有办法克服这个问题?在
这是我的代码库:for url in allUrls:
if url not in visitedUrls:
visitedUrls.append(url)
http=httplib2.Http()
response,content=http.request(url,headers={'User-Agent':'Crawler-Project'})
if (response.status/100<4):
soup=BeautifulSoup(content)
links=soup.findAll(