Python Forum
Need help with lxml.html and xpath
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with lxml.html and xpath
#4
(Apr-30-2021, 02:49 PM)spacedog Wrote: but those use bueatifulsoup which is too slow.
Can use lxml as parser in BS,i always do that.
soup = BeautifulSoup(response.content, 'lxml')
For your task if find ul XPath under products then can iterate over all li which will be children of that tag.
from lxml import html
import requests

url = 'https://www.yellowpages.com/nationwide/mip/toxglobal-diagnostics-llc-556885209?lid=1002050417627'
resonse = requests.get(url)
tree = html.fromstring(resonse.content)
prod = tree.xpath('//*[@id="business-info"]/dl/dd[3]/ul')
for tag in prod[0].getchildren():
    print(tag.text)
Output:
Walk In Clinic DNA Paternity Testing Genetic Testing Wellness Programs Senior Citizen Wellness Blood Tests Free Clinics Health Coaches Employee Health Programs Toxicology Labs Flu Shots
Reply


Messages In This Thread
Need help with lxml.html and xpath - by spacedog - Apr-29-2021, 10:58 PM
RE: Need help with lxml.html and xpath - by Larz60+ - Apr-30-2021, 12:36 PM
RE: Need help with lxml.html and xpath - by snippsat - Apr-30-2021, 03:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 1,029 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  reading html and edit chekcbox to html jacklee26 5 3,223 Jul-01-2021, 10:31 AM
Last Post: snippsat
  HTML to Python to Windows .bat and back to HTML perfectservice33 0 2,006 Aug-22-2019, 06:31 AM
Last Post: perfectservice33
  lxml - etree/lxml need help storing variable for most inserted element goeb 0 2,610 Apr-01-2019, 03:09 AM
Last Post: goeb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020