Skip to content

Conversation

Dhallod07
Copy link

web scraping program...

Copy link

@Alperencode Alperencode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use more specified variable names and definitions to keep your code clean. I just suggested and change them for you.

res = requests.get("https://www.amazon.in/s?bbn=976419031&rh=n%3A976419031%2Cp_89%3Arealme&dc&qid=1624216249&rnid=3837712031&ref=lp_976420031_nr_p_89_3", headers = headers)
bs = BeautifulSoup(res.text, "html.parser")
print(bs.title.string)
print(bs.find_all("div", {"class" : "s-image-square-aspect"}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use:
print(bs.find_all("div",class_="s-image-square-aspect"))

bs = BeautifulSoup(res.text, "html.parser")
print(bs.title.string)
print(bs.find_all("div", {"class" : "s-image-square-aspect"}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a variable for div section, then use this on for loop:
div_section = bs.find_all("div",class_="s-image-square-aspect")

print(bs.title.string)
print(bs.find_all("div", {"class" : "s-image-square-aspect"}))

for x in bs.find_all("div", {"class" : "s-image-square-aspect"}):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use more specified variable names like:
for div in div_section:
print(div.text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants