Skip to content
Advertisement

Webscraping a particular element of html

I’m having trouble scraping information from government travel advice websites for a research project I’m doing on Python.

I’ve picked the Turkey page but the logic could extend to any country.

The site is “https://www.gov.uk/foreign-travel-advice/turkey/safety-and-security

The code I’m using is:

JavaScript

At the moment this is extracting all the html of the page. Having inspected the website the information I am interested in is located in:

JavaScript

Does anyone know how to amend the code above to only extract that part of the html?

Thanks

Advertisement

Answer

If you are only interested in data located inside govuk-govspeak direction-ltr class, therefore you can try these steps :

Beautiful Soup supports the most commonly-used CSS selectors. Just pass a string into the .select() method of a Tag object or the BeautifulSoup object itself. For class use . and for id use #

JavaScript
Advertisement