With the help of thenewboston I was able to create a nice little web crawler in python. After watching his videos I played around with it and added a couple of things to it. I've tried to make it infinite as in it will get every link on every link every recorded, but I have failed in doing so. I also have a problem of recording the same link more than once? How would I go about fixing this problem?
Thank you in advance, this is my code.
import requests
from bs4 import BeautifulSoup
def spider(max_pages):
page = 1
while page <= max_pages:
url = ''
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
for link in soup.findAll("a"):
href = link.get("href")
title = link.get("title")
links = []
#print(href)
#print(title)
try:
get_single_user_data(href)
except:
pass
page += 1
def get_single_user_data(user_url):
source_code = requests.get(user_url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
#for item_name in soup.findAll('span', {'id':'mm-saleDscPrc'}):
# print(item_name.string)
for link in soup.findAll("a"):
href = link.get("href")
print(href)
spider(1)
Aucun commentaire:
Enregistrer un commentaire