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
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 81 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  How to get the href value of a specific word in the html code julio2000 2 171 Mar-05-2020, 07:50 PM
Last Post: julio2000
  Help on parsing simple text on HTML amaumox 5 296 Jan-03-2020, 05:50 PM
Last Post: amaumox
  Extract text between bold headlines from HTML CostasG 1 319 Aug-31-2019, 10:53 AM
Last Post: snippsat
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 452 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,375 Aug-06-2019, 07:23 AM
Last Post: fishhook
  Getting a specific text inside an html with soup mathieugrimbert 9 4,138 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert
  BeautifulSoup4, How to get an HTML tag with specific class. Broadsworde 6 2,866 Nov-22-2018, 05:25 PM
Last Post: snippsat
  XML Parsing - Find a specific text (ElementTree) TeraX 3 1,077 Oct-09-2018, 09:06 AM
Last Post: TeraX
  Beutifulsoup: how to pick text that's not in HTML tags? pitonas 4 1,008 Oct-08-2018, 01:43 PM
Last Post: pitonas

Forum Jump:

Users browsing this thread: 1 Guest(s)