我正准备在this俄语网站上制作小型网络抓取脚本。该脚本必须找到所有可用的医生。
遇到一些问题,无法在“Запись”标签中隐藏类。 经过研究后,我找到了Selenium模块,这是我的代码:
url = 'https://samozapis-spb.ru/moskovskiy-rayon/ctomatologicheskaya-poliklinika-no12'
from time import sleep
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
opts = Options()
prefs = {"profile.managed_default_content_settings.images": 2}
opts.add_experimental_option("prefs", prefs)
browser = Chrome(options=opts)
browser.get(url)
elems = browser.find_elements_by_css_selector('tr')
print('running chrome')
while True:
#print(browser.session_id)
elem = browser.find_element_by_id('show_app')
elem.click()
sleep(5)
elem = browser.find_element_by_css_selector("a[class='ax list-group-item']")
elem.click()
doctors = browser.find_elements_by_css_selector("a[class='ax list-group-item']")[2:]
tallons = {}
for doc in doctors:
temp = doc.text.split('\n')
if len(temp) == 2:
tallons[temp[1]]=temp[0]
print(tallons)
browser.refresh()
sleep(300)
此脚本有效,但我不喜欢它打开浏览器窗口。
答案 0 :(得分:1)
您只需在declare type RequiredProps = {
name: any,
dob: any,
age: any,
}
declare type AllKeys<T extends RequiredProps> = keyof T;
declare type SomeKeys<T extends RequiredProps> = Exclude<keyof T, "age">;
function Test<C extends RequiredProps>() {
const props1: AllKeys<C> = "name";
const props2: SomeKeys<C> = "name"; //Error: Type '"name"' is not assignable to type 'Exclude<keyof C, "age">'
}
中搜索POST正文并设置正确的标头即可抓取ajax请求
data-lid