Python Forum
How to get the href value of a specific word in the html code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the href value of a specific word in the html code
#2
As a example to get the Cargo Pant.
Will use CSS Selector the can target a specific tag.
import requests
from bs4 import BeautifulSoup

url = 'https://www.supremenewyork.com/shop/all/pants'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
cargo_pants = soup.select_one('#container > article:nth-child(4) > div > a')
Usage for getting href and src.
Output:
>>> cargo_pants <a href="/shop/pants/xz7ypjoam/yd2ny9jom" style="height:150px;"><img alt="Zhlkcvj 5dw" height="150" src="//assets.supremenewyork.com/187255/vi/zhlKcVj_5dw.jpg" width="150"/></a> >>> cargo_pants.get('href') '/shop/pants/xz7ypjoam/yd2ny9jom' >>> cargo_pants.img.get('src') '//assets.supremenewyork.com/187255/vi/zhlKcVj_5dw.jpg
Now you are using requests-html which you should mention as this is not at all common knowledge.
If would recommend to learn the more standar way as i shown here.
To do the same as shown here you most read the doc for requests-html,it has support for both CSS Selector and XPath Selector,so it shold work there to.
As i mention in your other post the lack of updates an response in Issues Tracker is a concern for this library.
Reply


Messages In This Thread
RE: How to get the href value of a specific word in the html code - by snippsat - Mar-05-2020, 03:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Populating list items to html code and create individualized html code files ChainyDaisy 0 1,614 Sep-21-2022, 07:18 PM
Last Post: ChainyDaisy
  Python Obstacles | Karate | HTML/Scrape Specific Tag and Store it in MariaDB BrandonKastning 8 3,245 Nov-22-2021, 01:38 AM
Last Post: BrandonKastning
  Extract Href URL and Text From List knight2000 2 9,311 Jul-08-2021, 12:53 PM
Last Post: knight2000
  BeautifulSoup pagination using href rhat398 1 2,451 Jun-30-2021, 10:55 AM
Last Post: snippsat
  Accessing a data-phone tag from an href KatMac 1 2,930 Apr-27-2021, 06:18 PM
Last Post: buran
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,710 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Monitor specific line of code and get alert Olimpiarob 0 1,557 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  How to fix looking specific word in a webpage BSOD 0 1,876 Jun-16-2020, 08:01 PM
Last Post: BSOD
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,403 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Web crawler extracting specific text from HTML lewdow 1 3,444 Jan-03-2020, 11:21 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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