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
I want to create a code wich gets the href=... of a specific name in the html code. A part of the html code looks like this:

class="name-link" href="/shop/pants/xz7ypjoam/i4lsmo5e7">Cargo Pant</a> == $0

there are more parts in the html code that look like this. Cause there are multiple products on the website (Supreme). I have got the name of the product -> Cargo Pant . Does someone know how I can get the href value from this specific line instead of a other line in the html code wich also includes a href= ? This was my code wich printed out all the href links on the page. But i just want that specific link from the product with Tupac Hologram Tee as the name.
session = HTMLSession()
r = session.get(url)
word = r.html.links
This is my code uptill now. This prints out all the href values on the page. But i just want a specific value. The url to the page is:
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 = ''
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.
>>> cargo_pants <a href="/shop/pants/xz7ypjoam/yd2ny9jom" style="height:150px;"><img alt="Zhlkcvj 5dw" height="150" src="//" width="150"/></a> >>> cargo_pants.get('href') '/shop/pants/xz7ypjoam/yd2ny9jom' >>> cargo_pants.img.get('src') '//
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.
Yeah I understand those lines. But the thing is, that on a dropday of supreme, where they drop limited items wich sellout fast. I don't know the place (and also not the css value)on the website of the product that I want to buy. That's why I want to get the href value (product link) that is linked to the wanted product name, wich is (in this example) Cargo Pant. So I want to create a code that finds the href value from the wanted name in the html code. But I don't really know how to :/

Possibly Related Threads…
Thread Author Replies Views Last Post
  Monitor specific line of code and get alert Olimpiarob 0 259 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  How to fix looking specific word in a webpage BSOD 0 293 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 443 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Web crawler extracting specific text from HTML lewdow 1 1,051 Jan-03-2020, 11:21 PM
Last Post: snippsat
  Web Scraping on href text Superzaffo 11 1,498 Nov-16-2019, 10:52 AM
Last Post: Superzaffo
  spliting html code with br tag yokaso 11 3,696 Aug-07-2019, 03:18 PM
Last Post: snippsat
  How do I extract specific lines from HTML files before and after a word? glittergirl 1 2,818 Aug-06-2019, 07:23 AM
Last Post: fishhook
  Getting a specific text inside an html with soup mathieugrimbert 9 6,266 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert
  [split] How to find a specific word in a webpage and How to count it. marpop 2 1,304 Mar-12-2019, 08:25 AM
Last Post: snippsat
  Embedding HTML Code in Python kendias 5 1,134 Jan-27-2019, 01:43 AM
Last Post: kendias

Forum Jump:

User Panel Messages

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