lundi 2 septembre 2019

How can i find the exact div from a google web page?

I am trying to a link from a google web page

this is my google link

http://www.google.hr/search?tbs=sbi:AMhZZivAbmp1vNv84BUN_15eAF4A-Fyq8GEnTwPutOLbPxBYm8PEDxsYkRUJf6Zm2jkCy2VsKuq6cgcLxh8zP42aiJRF7zvdl1NN1rpKF4fNpiVsZLOqdRlr6rIuU80w4j2ELhsNiK8pIz5nUWKEHnksVtCNZegq5QOJyblNFwY6Qux1sKzo8txDe79S50tSUKYju1nKgaVcA8XgyfG4wzH0LeWKLQGYR3dt0Iqll6ZNP1HVYFoK7lkl3VXEog3mdniaU32KYi7UfdVnjqw-3J7diN7_1eXRaEV6VSxlpcNfPK9J9TPZ4COFEpDWjh2WbKf--t3Bd_1uvu_1

import libraries

from urllib.request import urlopen from bs4 import BeautifulSoup

specify the url

fetchUrl = "http://www.google.hr/search?tbs=sbi:AMhZZivAbmp1vNv84BUN_15eAF4A-Fyq8GEnTwPutOLbPxBYm8PEDxsYkRUJf6Zm2jkCy2VsKuq6cgcLxh8zP42aiJRF7zvdl1NN1rpKF4fNpiVsZLOqdRlr6rIuU80w4j2ELhsNiK8pIz5nUWKEHnksVtCNZegq5QOJyblNFwY6Qux1sKzo8txDe79S50tSUKYju1nKgaVcA8XgyfG4wzH0LeWKLQGYR3dt0Iqll6ZNP1HVYFoK7lkl3VXEog3mdniaU32KYi7UfdVnjqw-3J7diN7_1eXRaEV6VSxlpcNfPK9J9TPZ4COFEpDWjh2WbKf--t3Bd_1uvu_1"

Connect to the website and return the html to the variable ‘page’

try: page = urlopen(fetchUrl) except: print("Error opening the URL")

parse the html using beautiful soup and store in variable soup

soup = BeautifulSoup(page, 'html.parser') all_div = soup.find("div", {"class": "e2Bnf U7izfe"})

print("content:",all_div)

print("c_len:",len(content))

At the end i had to find a specific link from a div class="e2Bnf U7izfe"

but i am getting some random link




Aucun commentaire:

Enregistrer un commentaire