0
http://www.qchp.org.qa/en/Pages/searchpractitioners.aspx에서 정보를 스크랩하려고합니다. 페이지 페이지 변경의 하단에 정보가 동적으로 자바 스크립트 Selenium scrapy python : csv/jsob에 데이터가 없습니다.
- 선택 "치과 의사"나는 다음을 수행 할 실무자 이름의 하이퍼 링크를 클릭하면 팝업이 나타납니다.
- 각 개인에 대한 json/csv 파일에 모든 정보를 저장하고 싶습니다.
저장 영역의 정보를 변경하는 페이지 하단에 링크 된 다른 페이지의 정보도 원합니다.
데이터를 json 파일로 내보내려고했지만 빈 파일이 생성되었습니다. 콘솔에 오류가 표시되지 않습니다.
여기 spider.py
from scrapy.spider import Spider
from scrapy.selector import Selector
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from scrapytutorial.items import SchItem
from selenium.webdriver.support.ui import Select
class DmozSpider(Spider):
name = "sch"
driver = webdriver.Firefox()
driver.get("http://www.qchp.org.qa/en/Pages/searchpractitioners.aspx")
dropdown = driver.find_element_by_name("ctl00$m$g_28bc0e11_4b8f_421f_84b7_d671de504bc3$ctl00$drp_practitionerType")
all_options = dropdown.find_elements_by_tag_name("option")
for option in all_options:
if option.get_attribute("value") == "4": #Dentist
option.click()
break
driver.find_element_by_name("ctl00$m$g_28bc0e11_4b8f_421f_84b7_d671de504bc3$ctl00$Searchbtn").click()
def parse(self, response):
all_docs = element.find_elements_by_tag_name("td")
for name in all_docs:
name.click()
alert = driver.switch_to_alert()
sel = Selector(response)
ma = sel.xpath('//table')
items = []
for site in ma:
item = SchItem()
item['name'] = site.xpath("//span[@id='PractitionerDetails1_lbl_Name']/text()").extract()
item['profession'] = site.xpath("//span[@id='PractitionerDetails1_lbl_Profession']/text()").extract()
item['scope_of_practise'] = site.xpath("//span[@id='PractitionerDetails1_lbl_sop']/text()").extract()
item['instituition'] = site.xpath("//span[@id='PractitionerDetails1_lbl_institution']/text()").extract()
item['license'] = site.xpath("//span[@id='PractitionerDetails1_lbl_LicenceNo']/text()").extract()
item['license_expiry_date'] = site.xpath("//span[@id='PractitionerDetails1_lbl_LicenceExpiry']/text()").extract()
item['qualification'] = site.xpath("//span[@id='PractitionerDetails1_lbl_Qualification']/text()").extract()
items.append(item)
return items
는
class SchItem(Item):
name = Field()
profession = Field()
scope_of_practise = Field()
instituition = Field()
license = Field()
license_expiry_date = Field()
qualification = Field()
사용중인 전체 코드가 표시되지 않는 것 같습니다. 이'parse()'메소드는 아마 거미 거미의 일부분 일 것이다. – alecxe
이것은 완전한 코드입니다. 나는 치료법을 사용하지 않고 있습니다 ... 치료법을 사용해야합니까? –
아니요, 치료는 여기에 필요하지 않지만 추가 데이터 처리에도 사용할 수 있습니다. 그런 다음'Scrapy '를 사용하지 않는다면'parse()'메소드는 여기서는 관련이 없다. 질문에서 명확성을 제거하는 것을 고려하십시오. 감사. – alecxe