Python Forum
How to append multiple <class 'str'> into a single List
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append multiple <class 'str'> into a single List
#1
I have a variable called "link_list" that prints out multiple game-id URLs which I, using pythonic means, procured from a sports website. The terminal output looks something like this:

print(link_list)


https://www.pcb.com.pk/match_detail.php?match_id=21782
https://www.pcb.com.pk/match_detail.php?match_id=21790
https://www.pcb.com.pk/match_detail.php?match_id=21798
https://www.pcb.com.pk/match_detail.php?match_id=21812
https://www.pcb.com.pk/match_detail.php?match_id=21822
If I print using print(type(variable)) it shows the following <class 'str'> fields for each line

print(type(link_list))

<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
Now what I want is, to merge these results (URLs) in the form of a list so I can then run a selenium code snippet later on to get relevant data from these. How do I go about doing this? Any assistance on the matter would be appreciated.


Also here's my code for how I am procuring these values [THIS IS JUST FOR REFERENCE ONLY]:

#Importing all the necessary Libraries
import PySimpleGUI as sg
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import urllib.request
from selenium.webdriver.support.ui import Select
import pandas as pd
import re
import itertools


# Developing Simple Front End
label = [sg.Text("Please Enter Link")]
link = [sg.Input(enable_events=True, key='link')]
scrape_btn = [sg.Button("Scrape")]
exit_btn = [sg.Button("Exit")]
select_discipline = ['batting', 'bowling']
dropdown_discipline = [sg.Combo(select_discipline, enable_events=True, key='selection')]

#Developing Layout and Window Pane
layout = [label, link, dropdown_discipline, scrape_btn, exit_btn]
window = sg.Window("PCB Domestic Numbers", layout)


while True:
	event, values = window.read()
	
	if event == "Scrape":
		combo = values['selection']
		link = values['link']
		if combo == 'batting':
			driver = webdriver.Chrome()
			driver.get(link)
			select = Select(driver.find_element_by_name('new_page_limit'))
			select.select_by_value('all')
			html = driver.page_source
			soup = BeautifulSoup(html, "html.parser")
			target_name = html[html.find("<h1 class="):html.find("</h1>")]
			name = target_name.split('by ')[1]
			link_list = []
			for link in soup.findAll('a'):
				if "match_id" in link.get('href'):
					link_list = link
					link_list = str(link_list)
					start = '="'
					end = '">'
					link_list = link_list.split(start)[1].split(end)[0]
					print(type(link_list))
			driver.close()
			window.close()

		elif combo == 'bowling':
			print(combo)
		

	if event == "Exit" or event == sg.WIN_CLOSED:
		break

window.close()
Reply


Messages In This Thread
How to append multiple <class 'str'> into a single List - by ahmedwaqas92 - Jan-07-2021, 05:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 343 Mar-14-2024, 06:26 PM
Last Post: flash77
  Can I use logging in a class (without multiple messages) mevan 2 535 Oct-16-2023, 11:08 PM
Last Post: mevan
  How to read module/class from list of strings? popular_dog 1 424 Oct-04-2023, 03:08 PM
Last Post: deanhystad
Question How to append integers from file to list? Milan 8 1,360 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  Create multiple/single csv file for each sql records mg24 6 1,323 Sep-29-2022, 08:06 AM
Last Post: buran
  read a text file, find all integers, append to list oldtrafford 12 3,371 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Using .append() with list vs dataframe Mark17 7 9,899 Jun-12-2022, 06:54 PM
Last Post: Mark17
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,268 Dec-04-2021, 08:33 PM
Last Post: Ascalon

Forum Jump:

User Panel Messages

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