Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Web crawler extracting specific text from HTML
Hi - I've just started to learn how to use python and am exploring the elements of a web crawler. I'm trying to extract the text that follows "Licences" from this page (in this instance, I would like the result to be 'COPD Licence' for example).

So far I have the basics:
import requests
from bs4 import BeautifulSoup

result = requests.get(
src = result.content
soup = BeautifulSoup(src, 'html.parser')
but then I'm struggling to successfully define the specific element that I'm going after - can anyone help please?
Can use CSS selector here as many of class name are the same.
>>>'div.MedicineDeviceProduct-detail > div > div:nth-child(2) > div > span > ul > li')
[<li>COPD Licence</li>]
>>> soup.select_one('div.MedicineDeviceProduct-detail > div > div:nth-child(2) > div > span > ul > li')
<li>COPD Licence</li>
>>> soup.select_one('div.MedicineDeviceProduct-detail > div > div:nth-child(2) > div > span > ul > li').text
'COPD Licence'
You can find selector in browser and copy it.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help on parsing simple text on HTML amaumox 5 229 Jan-03-2020, 05:50 PM
Last Post: amaumox
  Extract text between bold headlines from HTML CostasG 1 270 Aug-31-2019, 10:53 AM
Last Post: snippsat
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 388 Aug-25-2019, 01:13 AM
Last Post: kawasso
  How do I extract specific lines from HTML files before and after a word? glittergirl 1 2,300 Aug-06-2019, 07:23 AM
Last Post: fishhook
  Getting a specific text inside an html with soup mathieugrimbert 9 3,092 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert
  BeautifulSoup4, How to get an HTML tag with specific class. Broadsworde 6 2,093 Nov-22-2018, 05:25 PM
Last Post: snippsat
  XML Parsing - Find a specific text (ElementTree) TeraX 3 1,004 Oct-09-2018, 09:06 AM
Last Post: TeraX
  Beutifulsoup: how to pick text that's not in HTML tags? pitonas 4 906 Oct-08-2018, 01:43 PM
Last Post: pitonas
  Decoding html to text string PeterPython 1 681 Aug-12-2018, 07:23 PM
Last Post: Larz60+
  Beautiful Soup - Delete All HTML - Except Specific Classes dj99 7 2,143 Jul-13-2018, 08:18 AM
Last Post: dj99

Forum Jump:

Users browsing this thread: 1 Guest(s)