我是Python的新手,正在尝试抓取一个动态生成的表。我已经足够打开页面,输入搜索,并显示结果表。我在抓取结果时遇到了麻烦,我注意到结果的特定文本不是HTML的一部分。到目前为止,这是我的代码,感谢大家的帮助。
## module importation
import os, requests, bs4, openpyxl, webbrowser, lxml, html5lib, re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print('Type in the FIRST NAME of the individual.')
#I've been using [Mike] here.
firstName = input()
print('Thanks. Now type in the individual\'s LAST NAME.')
#I've been using [Jones] here.
lastName = input()
browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
#BoP inmate locator
#Goes to BoP website
browser.get('https://www.bop.gov/inmateloc/')
res = requests.get('https://www.bop.gov/inmateloc/')
#Clicks Search by name option (just in case)
searchByNameButton = browser.find_element_by_css_selector("#ui-id-1")
searchByNameButton.click() # clicks the Search by Name Button
#enters first name
bopSearchFirstNameElem =
browser.find_element_by_css_selector('#inmNameFirst')
bopSearchFirstNameElem.send_keys(firstName)
#enters last name
bopSearchLastNameElem =
browser.find_element_by_css_selector('#inmNameLast')
bopSearchLastNameElem.send_keys(lastName)
# Clicks search
searchSubmitButton =
browser.find_element_by_css_selector('#searchNameButton')
searchSubmitButton.click() # clicks the Search Button on the BoP page
# Scrape table results
bopResultsPage = bs4.BeautifulSoup(res.text, 'html.parser')
https://stackoverflow.com/questions/52322221
复制相似问题