Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Web crawler extracting specific text from HTML
#1
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(
    "https://www.rightbreathe.com/medicines/eklira-322microgramsdose-genuair-astrazeneca-uk-ltd-60-dose/?s=")
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?
Quote
#2
Can use CSS selector here as many of class name are the same.
>>> soup.select('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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Extracting html data using attributes WiPi 14 435 May-04-2020, 02:04 PM
Last Post: snippsat
  Help extracting text from element jpdallas 7 263 Apr-30-2020, 06:26 AM
Last Post: anbu23
  Extracting Text in a canvas using chain actions law 3 463 Apr-22-2020, 11:45 AM
Last Post: Larz60+
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 168 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 270 Mar-05-2020, 07:50 PM
Last Post: julio2000
  Help on parsing simple text on HTML amaumox 5 406 Jan-03-2020, 05:50 PM
Last Post: amaumox
  Extract text between bold headlines from HTML CostasG 1 383 Aug-31-2019, 10:53 AM
Last Post: snippsat
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 550 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,483 Aug-06-2019, 07:23 AM
Last Post: fishhook
  Getting a specific text inside an html with soup mathieugrimbert 9 4,949 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert

Forum Jump:


Users browsing this thread: 1 Guest(s)