我正在使用Python机器检查考试的日期/时间,如果结果中有特定的日期/时间,我会发送电子邮件给某人(结果页面截图)
import mechanize
from BeautifulSoup import BeautifulSoup
URL = "http://secure.dre.ca.gov/PublicASP/CurrentExams.asp"
br = mechanize.Browser()
response = br.open(URL)
# there are some errors in doctype and hence filtering the page content a bit
response.set_data(response.get_data()[200:])
br.set_response(response)
br.select_form(name="entry_form")
# select Oakland for the 1st set of checkboxes
for i in range(0, len(br.find_control(type="checkbox",name="cb_examSites").items)):
if i ==2:
br.find_control(type="checkbox",name="cb_examSites").items[i].selected =True
# select salesperson for the 2nd set of checkboxes
for i in range(0, len(br.find_control(type="checkbox",name="cb_examTypes").items)):
if i ==1:
br.find_control(type="checkbox",name="cb_examTypes").items[i].selected =True
reponse = br.submit()
print reponse.read()我能够得到响应,但由于某种原因,表中的数据丢失了。
下面是初始html页面中的按钮
<input type="submit" value="Get Exam List" name="B1">
<input type="button" value="Clear" name="B2" onclick="clear_entries()">
<input type="hidden" name="action" value="GO">输出的一部分(提交响应),其中实际数据位于
<table summary="California Exams Scheduling" class="General_list" width="100%" cellspacing="0"> <EVERTHING INBETWEEN IS MISSING HERE>
</table>表中的所有数据都丢失了。我从chrome浏览器中提供了表格元素的屏幕截图。
更新-看起来我的问题可能与this question有关,并且正在尝试我的选择。我尝试了下面的答案之一,但无法在数据中看到任何tr元素(尽管当我手动检查时可以在页面源中看到这一点)。
soup.findAll('table')[0].findAll('tr')

对此进行了更新,使其使用selenium,不久将尝试进一步改进。
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import urllib3
myURL = "http://secure.dre.ca.gov/PublicASP/CurrentExams.asp"
browser = webdriver.Firefox() # Get local session of firefox
browser.get(myURL) # Load page
element = browser.find_element_by_id("Checkbox5")
element.click()
element = browser.find_element_by_id("Checkbox13")
element.click()
element = browser.find_element_by_name("B1")
element.click()发布于 2021-04-03 01:49:02
五年后,也许这能帮到一个人。我把你的问题当作训练练习。我使用请求包完成了它。(我使用python 3.9)
以下代码分为两部分:
"d“包含您想要的数据。我还没发邮件呢。
https://stackoverflow.com/questions/35827238
复制相似问题