Reputation: 1
This is my code so far:
s = BS(r.content, 'lxml')
findDiv = s.find('div', {'id':'BodyContentPlaceholder_T00DF23F8005_Col00'})
findTable = findDiv.findAll('table', {'style':'width: 100%; border-collapse: collapse;'})
for table in findTable:
rows = table.findAll('tr')
rows = rows[1:]
for row in rows:
cells = row.findAll('td')
extension = cells[3].button.input.text
print('docs page ' + str(extension))
#extention = re.compile(pattern, text)
docpage_url_ending = cells[3].find('value')
print('url ' + str(docpage_url_ending))
I'm trying to get navigateUrl text from this
<input id="ctl00_BodyContentPlaceholder_C013_RadListView1_ctrl1_rlb1_ClientState" name="ctl00_BodyContentPlaceholder_C013_RadListView1_ctrl1_rlb1_ClientState" type="hidden" autocomplete="off" value="{"text":"Documents","value":"","target":"","navigateUrl":"/procurement/procurement-bids/constructionprocurementdetail?Title=Lakeland Adult Daycare Center Roof Replacement 18-785","primary":false}">
Upvotes: 0
Views: 1285
Reputation: 495
That's how you get to your navigateUrl
:
import json
from bs4 import BeautifulSoup as BS
s = BS(r.content, 'lxml')
findDiv = s.find('div', {'id':'BodyContentPlaceholder_T00DF23F8005_Col00'})
findTable = findDiv.findAll('table', {'style':'width: 100%; border-collapse: collapse;'})
for table in findTable:
rows = table.findAll('tr')
rows = rows[1:]
for row in rows:
cells = row.findAll('td')
extension = cells[3].button.input.text
print('docs page ' + str(extension))
#extention = re.compile(pattern, text)
docpage_url_ending = json.loads(cells[3].button.input.attr['value'])['navigateUrl']
print('url ' + docpage_url_ending)
Upvotes: 0
Reputation: 4128
import json
import bs4
import urllib
data = '<input id="ctl00_BodyContentPlaceholder_C013_RadListView1_ctrl1_rlb1_ClientState" name="ctl00_BodyContentPlaceholder_C013_RadListView1_ctrl1_rlb1_ClientState" type="hidden" autocomplete="off" value="{"text":"Documents","value":"","target":"","navigateUrl":"/procurement/procurement-bids/constructionprocurementdetail?Title=Lakeland Adult Daycare Center Roof Replacement 18-785","primary":false}">'
# cook up some soup
soup = bs4.BeautifulSoup(data)
# extract the relevant attribute
vals_as_string = soup.html.body.input.attrs['value']
# it's urlencoded, so decode it
unquoted_vals_as_string = urllib.parse.unquote(vals_as_string)
# turns out, it's json
vals_as_json = json.loads(unquoted_vals_as_string)
# well, json converts to dict, so there's our target
navigateUrl = vals_as_json['navigateUrl']
Upvotes: 1