Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Scraping on href text
#11
Ok. No problem.
I'm in no hurry.
Thank you

:-D
Reply
#12
I wrote this code.. From our exaple (Thank you)
from bs4 import BeautifulSoup
import requests
 
 
class ScrapeOrchids:
    def __init__(self):
        self.main_url = 'http://www.orchidspecies.com/indexe-ep.htm'
        self.links = {}
        self.get_initial_list()
        self.show_links()
     
    def get_initial_list(self):
        baseurl = 'http://www.orchidspecies.com/'
        response = requests.get(self.main_url)
        if response.status_code == 200:
            page = response.content
            soup = BeautifulSoup(page, 'lxml')
            # css_select link can be found using browser inspect element, then right click-->Copy-->CSS_Selector
            for i in soup.select("li"):
                 #print(i.a.text)
                if 'Epiblastus lancipetalus' in i.a.text:
                    #print(i.a.get('href'))
                    self.links[i.a.text.strip()] = f"{baseurl}{i.a.get('href')}"
          
        else:
            print(f"Problem fetching {self.main_url}")
 
    def show_links(self):
        for key, value in self.links.items():
            print(f"{key}: {value}")
 
 
if __name__ == '__main__':
    ScrapeOrchids()
this is the result
Output:
Epiblastus lancipetalus Schltr. 1911: http://www.orchidspecies.com/epiblancipetalus.htm
and is what I want.
Now I need to get the new link and in the page save the image of the orchid in a excel file. :-(
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extract Href URL and Text From List knight2000 2 8,619 Jul-08-2021, 12:53 PM
Last Post: knight2000
  BeautifulSoup pagination using href rhat398 1 2,350 Jun-30-2021, 10:55 AM
Last Post: snippsat
  Accessing a data-phone tag from an href KatMac 1 2,863 Apr-27-2021, 06:18 PM
Last Post: buran
  Scraping all website text using Python MKMKMKMK 1 2,050 Nov-26-2020, 10:35 PM
Last Post: Larz60+
  Scraping text from application? kamix 1 1,548 Sep-25-2020, 10:53 PM
Last Post: Larz60+
  How to get the href value of a specific word in the html code julio2000 2 3,143 Mar-05-2020, 07:50 PM
Last Post: julio2000
  scraping in a text/javascript saasyp 1 2,181 Aug-31-2019, 11:39 AM
Last Post: metulburr
  Scrapy Picking What to Output Href or Img soothsayerpg 1 2,677 Aug-02-2018, 10:59 AM
Last Post: soothsayerpg
  Flask - Opening second page via href is failing - This site can’t be reached rafiPython1 2 5,433 Apr-11-2018, 08:41 AM
Last Post: rafiPython1

Forum Jump:

User Panel Messages

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