我希望我能找到你。你知道吗
作为Python和webscraping的新手,我希望您能帮助我理解我在一个项目中遇到的问题。你知道吗
为了给你一些背景,我目前正在设计一个脚本,允许居住在法国的个人自动检查可用的时间段,以安排在他们居住的地区的法国公民身份申请过程的预约。由于时隙非常难以获得,而且在用户反馈的情况下,时隙来得快去得也快,因此这个过程成为许多人不断感到沮丧的根源。你知道吗
下面的代码是脚本的摘录,该脚本连接到学区的网站,选择一个可用的展位,并返回可用性页面的“action”参数。time.sleep
函数用于避免网站使用的代理过载(因为它容易出现502个错误),我正在打印当前url和操作值,以验证它们是否与浏览器中的值对齐:
from selenium import webdriver
from bs4 import BeautifulSoup
import requests
import time
url = "http://www.hauts-de-seine.gouv.fr/booking/create/4462/1"
booth_selection = "//input[@value='7070'][@name='planning']"
booking_selector = "//input[@value='Etape suivante'][@name='nextButton']"
browser = webdriver.Safari()
browser.maximize_window()
browser.get(url)
time.sleep(5)
booth_selection = browser.find_element_by_xpath(booth_selection)
booth_selection.click()
time.sleep(5)
booking_submit = browser.find_element_by_xpath(booking_selector)
booking_submit.click()
browser.implicitly_wait(5)
page = browser.current_url
print(page)
agent = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'}
page_response = requests.get(page, headers=agent)
soup = BeautifulSoup(page_response.text, 'lxml')
action = soup.find('form', id='FormBookingCreate').get('action')
print(action)
time.sleep(10)
browser.close()
不幸的是,情况似乎并非如此,因为:
以下是Safari控制台的屏幕截图供参考:HTML code of resulting page
你能帮我理解为什么会这样吗?能做些什么来解决这个问题?你知道吗
提前谢谢。你知道吗
不断得到504错误,虽然你需要做一些挖掘。。。这是因为cookies为什么不能直接访问另一个URL。使用硒会很慢,我建议只使用
request
来处理这类事情。你知道吗我想这就是你要找的用于:你知道吗
我得到的输出是:-
以及
所以我所做的就是使用类名和id来获取所需的信息。如果需要,可以忽略选项部分。你知道吗
相关问题 更多 >
编程相关推荐