In attempting to read a webpage ("https://www.house.gov/representatives#by-name") I have managed to import a table using
tableText1 = WebExecute[browser, "JavascriptExecute" -> "return document.getElementById('by-name').innerText;"];
I've eventually been able to massage the text, which contains a number of line feeds and blanks and comas at different levels within the table as well as a variable number of columns in each row, into a single table of Dimensions[n,6] of which [11,3] are shown here. However, note that the now third column contains a rather inconsistent series of strings, which I would like to edit following each committee name by a linefeed ("\n") using a list of rules.
The subset of data for illustrative purposes is here:
table21 = {"Arrington, Jodey", "Texas 19th", "Ways and Means"},
{"Axne, Cynthia", "Iowa 3rd","AgricultureFinancial Services"},
{"Babin, Brian", "Texas 36th", "Transportation and InfrastructureScience,
Space, and Technology"}, \
{"Bacon, Don", "Nebraska 2nd", "AgricultureArmed Services"},
{"Baird, James", "Indiana 4th","AgricultureScience, Space, and Technology"},
{"Balderson, Troy", "Ohio 12th","Transportation and InfrastructureSmall
BusinessScience, Space, and Technology"},
{"Banks, Jim", "Indiana 3rd", "Armed ServicesEducation and LaborVeterans'
Affairs"},
{"Barr, Andy", "Kentucky 6th","Financial ServicesVeterans' Affairs"},
{"Barragán, Nanette", "California 44th","Homeland SecurityEnergy and
Commerce"},
{"Bass, Karen","California 37th", "Foreign AffairsJudiciary"},
{"Beatty, Joyce", "Ohio 3rd", "Financial Services"}}
As one can see the committee names in the 3rd column are not in a columnar form for each representative and the names run together. Because in the larger list there are many combinations of committees that can not be easily replaced by a single StringReplace[table21,{"a"->"a\n, "b->b\n"...}] expression, I have created a list of rules using Thread as follows:
committees = {"Agriculture", "Appropriations", "Armed Services",
"Budget", "Climate Change", "Education and Labor", "Ethics",
"Energy and Commerce", "Financial Services", "Foreign Affairs",
"Homeland Security", "Intelligence", "Judiciary",
"Modernization of Congress", "Natural Resources",
"Oversight and Reform", "Science, Space and Technology",
"Small Business", "Transportation and Infrastrure",
"Veterans' Affairs", "Ways and Means"}
addlinefeed[x_] := x ~~ "\n";
editedcommittees = addlinefeed /@ committees;
rules = Thread[committees -> editedcommittees];
Although I can convert the entire table to a String by doing a StringReplace to effect these edits, in doing so I lose the desirable list structure and getting it back is complicated by the presence of comas used differently in different elements within the list of lists.
How can I replace one column of this list of lists suitably edited using StringReplace in combination with my set of rules so that only this single suitably edited column appears as a column of columns within the list of lists, while leaving other columns within the list of lists unchanged?
I've tried various combinations of Replace, StringReplace, Map, and MapAt trying to take into account the suitable levels and parts to edit this one column leaving all others the same. However, I have not met with success. A few other questions give hints but I am stumped. How can this be done?