首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用python3和Selenium抓取动态生成的表

使用python3和Selenium抓取动态生成的表
EN

Stack Overflow用户
提问于 2018-09-14 05:46:04
回答 1查看 79关注 0票数 0

我是Python的新手,正在尝试抓取一个动态生成的表。我已经足够打开页面,输入搜索,并显示结果表。我在抓取结果时遇到了麻烦,我注意到结果的特定文本不是HTML的一部分。到目前为止,这是我的代码,感谢大家的帮助。

代码语言:javascript
复制
## 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')
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52322221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档