Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Scraping on href text
#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


Messages In This Thread
Web Scraping on href text - by Superzaffo - Nov-13-2019, 10:32 PM
RE: Web Scraping on href text - by Larz60+ - Nov-14-2019, 12:30 AM
RE: Web Scraping on href text - by Superzaffo - Nov-14-2019, 09:06 AM
RE: Web Scraping on href text - by Malt - Nov-14-2019, 10:27 AM
RE: Web Scraping on href text - by Larz60+ - Nov-14-2019, 10:54 AM
RE: Web Scraping on href text - by Superzaffo - Nov-14-2019, 08:20 PM
RE: Web Scraping on href text - by Superzaffo - Nov-14-2019, 10:05 PM
RE: Web Scraping on href text - by Larz60+ - Nov-15-2019, 02:33 AM
RE: Web Scraping on href text - by Superzaffo - Nov-15-2019, 08:10 AM
RE: Web Scraping on href text - by Larz60+ - Nov-15-2019, 12:43 PM
RE: Web Scraping on href text - by Superzaffo - Nov-15-2019, 01:18 PM
RE: Web Scraping on href text - by Superzaffo - Nov-16-2019, 10:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extract Href URL and Text From List knight2000 2 9,107 Jul-08-2021, 12:53 PM
Last Post: knight2000
  BeautifulSoup pagination using href rhat398 1 2,422 Jun-30-2021, 10:55 AM
Last Post: snippsat
  Accessing a data-phone tag from an href KatMac 1 2,906 Apr-27-2021, 06:18 PM
Last Post: buran
  Scraping all website text using Python MKMKMKMK 1 2,093 Nov-26-2020, 10:35 PM
Last Post: Larz60+
  Scraping text from application? kamix 1 1,601 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,223 Mar-05-2020, 07:50 PM
Last Post: julio2000
  scraping in a text/javascript saasyp 1 2,231 Aug-31-2019, 11:39 AM
Last Post: metulburr
  Scrapy Picking What to Output Href or Img soothsayerpg 1 2,719 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,502 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