抓取时在<strong>元素内查找课程

时间:2020-01-04 16:00:21

标签: python selenium web-scraping

我想在soccer matches website上检索下载链接。

enter image description here

使用以下脚本,我可以找到周围元素的位置:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://fullmatchsports.co/amiens-vs-psg-full-match-ligue-1-2018/')
soup = BeautifulSoup(driver.page_source, 'lxml')
download = driver.find_element_by_xpath('//*[@id="post-22276"]/div/div/p[3]/strong')

接下来,我想在“下载”中找到链接

links = download.findAll('a')

这将导致以下错误:

AttributeError: 'WebElement' object has no attribute 'findAll'

我不明白为什么它找不到这些类。如果检查页面,会发现这些类是“ strong”的一部分?

1 个答案:

答案 0 :(得分:1)

使用 BeautifulSoup

  • let recorder = RPScreenRecorder.shared() recorder.startCapture(handler: { [weak self](buffer, bufferType, err) in // ... }, completionHandler: { (error) in // 1. If the user chooses "Dont'Allow", the error message will print "The user declined application recording". Outside of that if an actual error occurs something else will print if let error = error { print(error.localizedDescription) print("The user choose Don't Allow") return } // 2. Check the other 2 options if self.recorder.isMicrophoneEnabled { print("The user choose Record Screen & Microphone") } else { print("The user choose Record Screen Only") } }) BeautifulSoup 方法
  • }, completionHandler: { (error) in if let error = error as NSError? { let rpRecordingErrorCode = RPRecordingErrorCode(rawValue: error.code) self.errorCodeResponse(rpRecordingErrorCode) } }) func errorCodeResponse(_ error: RPRecordingErrorCode?) { guard let error = error else { return } switch error { case .unknown: print("Error cause unknown") case .userDeclined: print("User declined recording request.") case .disabled: print("Recording disabled via parental controls.") case .failedToStart: print("Recording failed to start.") case .failed: print("Recording error occurred.") case .insufficientStorage: print("Not enough storage available on the device.") case .interrupted: print("Recording interrupted by another app.") case .contentResize: print("Recording interrupted by multitasking and content resizing.") case .broadcastInvalidSession: print("Attempted to start a broadcast without a prior session.") case .systemDormancy: print("Recording forced to end by the user pressing the power button.") case .entitlements: print("Recording failed due to missing entitlements.") case .activePhoneCall: print("Recording unable to record due to active phone call.") default: break } } IEnumerable<double> numbers = GetNumbers(); var queue = new Queue<double>(); foreach (var number in numbers) { var computed = Compute(number); queue.Enqueue(computed); } ,没有findAll方法。

这是错误的原因。这里是如何获取Selenium的下载链接:

download = driver.find_element_by_xpath('//*[@id="post-22276"]/div/div/p[3]/strong')