urllib을 사용하여 https 웹 사이트의 내용을 파이썬으로 추출하려고 시도했습니다. 나는 4 줄의 코드를 사용했다.는 urllib을 사용하여 https 사이트에서 python으로 데이터를 추출합니다 (귀하의 요청은 오류를 완료 할 수 없습니다).
import urllib
fhand = urllib.urlopen('https://www.tax.service.gov.uk/view-my-valuation/list-valuations-by-postcode?postcode=w1a&startPage=1#search-results')
for line in fhand:
print line.strip()
페이지가 파이썬에서 열릴 때 연결이 작동하는 것처럼 보입니다. 그러나 제목, 제목 및 단락 제목 아래에 내 출력에 몇 가지 다른 오류 메시지가 나타납니다. 출력물이 주소, 기본 요율 및 사례 번호와 같은 웹 사이트에서 사용할 수있는 데이터를 포함하는 일련의 html 태그 (예 : Google 크롬 개발자의 요소에 들어갈 경우 사용할 수있는 html)가 될 것으로 예상했습니다. 누군가 파이썬으로이 데이터를 가져 오는쪽으로 나를 안내 할 수 있습니까?
감사 & 감사
<!DOCTYPE html>
<html class="no-branding"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Your request cannot be completed - GOV.UK</title>
<link href="/edge-assets/gone.css" media="screen" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><link href="/edge-assets/ie.css" media="screen" rel="stylesheet" type="text/css"><![endif]-->
<link rel="icon" href="/edge-assets/govukfavicon.ico" type="image/x-icon" />
</head>
<body>
<div id="wrapper">
<div id="banner" role="banner">
<div class="inner">
<h1>
<a href="https://www.gov.uk/">
<img src="/edge-assets/govuk-logo.png" alt="GOV.UK">
</a>
</h1>
</div>
</div>
<div id="message" role="main">
<div class="inner">
<div id="detail">
<h2>Sorry, there was a problem handling your request.</h2>
<p class="call-to-action">Please try again shortly.</p>
</div>
<div id="footer">
</div>
</div>
</div>
</div>
</body></html>
print(requests.get(url).text)
이이 요청 패키지를 사용하려고 할 수 있습니다. 그것은 나를 위해 작동합니다. '가져 오기 요청' 'textout = requests.get ('https://www.tax.service.gov.uk/view-my-valuation/list-valuations-by-postcode?postcode=w1a&startPage=1#search -results '). 텍스트' '인쇄 textout' –내 의견을 서식을 지정할 수있을 것 같습니다! -_- –
Prateek에게 제안 해 주셔서 감사합니다. 요청은 강력한 도구로 보입니다. 나는 그것을 들여다 볼 것이다! –