Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Web Scraping Country name form google search?

$
0
0

@premsheth wrote:

Hi, Friends

I am new in Python and trying to do web scraping using python.
I have list of cities. Now I want to scrape country name according to city name using google search or any other method.
Can anyone have idea how can I do in python?

i got one code but it gives me all text of city which I search from google:

import urllib
from bs4 import BeautifulSoup
import requests
import webbrowser

text = 'Central London'
text = urllib.parse.quote_plus(text)

url = 'https://google.com/search?q=' + text

response = requests.get(url)

soup = BeautifulSoup(response.text, 'lxml')
for g in soup.find_all(class_='g'):
    print(g.text)
    print('-----')

output:

Central London - Wikipediahttps://en.wikipedia.org/wiki/Central_LondonCachedSimilarCentral London is the innermost part of London, in the United Kingdom, spanning 
several boroughs. Over time, a number of definitions have been used to define 
the scope of central London for statistics, urban planning and local government. 
Its characteristics are understood to include a high density built environment, 
high ...Characteristics - Definitions - London Plan
-----
Central London - visitlondon.comhttps://www.visitlondon.com/things-to-do/london-areas/centralCachedStep into the beating heart of London and lose yourself in its exciting mix of 
tradition, culture, commerce and innovation. Discover historical treasures at the 
British Museum, follow in the footsteps of the famous at Westminster Abbey or get 
a great aerial view from the London Eye.

I just want to country name
How can I do that? all help would be appreciate.

Thanks in Advance

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles