아래 코드를 볼 수 있습니다. 그것은 프로젝트 목록을 통해 실행하고 출력으로 테이블을 제공합니다. 내가 "get_text"을 삭제하면Python - HTML 태그 사이에 텍스트 가져 오기
Traceback (most recent call last):
File "save.py", line 104, in <module>
status = soup.find('span',{'class':'classname'}).get_text
AttributeError: 'NoneType' object has no attribute 'get_text'
이 상태 부분은 항상 출력으로 "없음"을 보여줍니다 속성 :
x = PrettyTable(["Soli", "Zusammenfassung", "Bearbeiter", "Status", "Termin"])
display = Display()
display.start()
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.example.com')
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from BeautifulSoup import BeautifulSoup
for j in range(0,len(total_tickets)):
url = driver.current_url
r = requests.get(url)
html_content = r.text
soup = BeautifulSoup(html_content, 'lxml')
ticket = driver.find_elements_by_xpath("//*[@id='ghx-issues-in-epic-table']/tbody/tr/td[2]/a")
ticket[j].click()
driver.get_screenshot_as_file("test.png")
worker = driver.find_element_by_xpath("//*[@id='peopledetails']/li/dl[1]/dd").find_element_by_class_name("user-hover").get_attribute("rel")
Soli = driver.find_element_by_xpath("//*[@id='key-val']").get_attribute("data-issue-key")
driver.find_element_by_xpath("//*[@id='summary-val']/span").click()
conclusion = driver.find_element_by_xpath("//*[@id='summary']").get_attribute("value")
status = soup.find('span',{'class':'classname'}).get_text
try:
termin = driver.find_element_by_xpath("//*[@id='datesmodule']").find_element_by_xpath("//*[@id='customfield_10090-val']/span[1]/time").get_attribute("datetime")
except NoSuchElementException:
termin = "No Deadline"
x.add_row([Soli, conclusion, worker, status, termin])
x.padding_width = 1
with open('file', 'w') as w:
w.write(str(x))
첫 번째 문제는,이 오류가 발생합니다.
이
는 텍스트를 얻을해야 HTML입니다. span 태그 사이에 "NEU"라는 텍스트가 표시되기를 원합니다.<li class="item item-right">
<div class="wrap">
<strong class="name">
Status:
</strong>
<span id="status-val" class="value">
<span class="classname" original-title="">
Neu
</span>
</span>
<span class="status-view">(<a href="#" class="classname">Arbeitsablauf anzeigen</a>)
</span>
</div>
</li>
의 클래스 사업부의 자료이고 문서의 최상위 레벨이 아니라 중첩 된 것인가? 그런데'xpath'를 통해 쉽게 접근 할 수 있습니다. –
'requests.get()'대신'driver.page_source'를 사용해야합니다. '요청'은 올바른 헤더를 사용하지 않으면 '셀레늄'과 다른 데이터를 얻을 수 있습니다. – furas