I've written a script in Python to scrape app name, developer and price from ITunes site.
In its first page there are 10 different recommended app links which my scraper is able to track down and scrape the aforesaid fields going to their concerning page. The quantity of the apps should be 11. Previously, the scraper was printing only 10 results skipping the content from first page. However, there is a line in my scraper (I've written a comment next to it to make you identify) which I've added in such a way so that the scraper do not fail to skip the content of first page from printing.
With this extra line in it, the scraper has got a clumsy look. It didn't impact on the performance, though! It runs smoothly now and brings results without leaving anything to complain. How can I give it a better look along with any improvement?
This is what I've written:
import requests
from bs4 import BeautifulSoup
main_link = "https://itunes.apple.com/us/app/candy-crush-saga/id553834731?mt=8"
def get_links(url):
response = requests.get(url)
get_content(url) # This is the very line which let the scraper harvest documents from the first page
soup = BeautifulSoup(response.text,"html.parser")
for title in soup.select("a.name"):
get_content(title.get("href"))
def get_content(new_links):
req = requests.get(new_links)
broth = BeautifulSoup(req.text,"html.parser")
item ={
"app_name": broth.select("h1[itemprop=name]")[0].text,
"developer": broth.select("div.left h2")[0].text,
"price": broth.select("div.price")[0].text
}
print(item)
get_links(main_link)