Python xpath=>;SyntaxError:无效语法
我是python的新手。我正在尝试抓取一些文本,但它不起作用。。。 这是我的密码Python xpath=>;SyntaxError:无效语法,python,xpath,web-crawler,Python,Xpath,Web Crawler,我是python的新手。我正在尝试抓取一些文本,但它不起作用。。。 这是我的密码 def parse(self,response): hxs = Selector(response) article_list = hsx.xpath('//*[@id="weather"]') print('##################### total_length : ' + str(len(article_list))) for a in article
def parse(self,response):
hxs = Selector(response)
article_list = hsx.xpath('//*[@id="weather"]')
print('##################### total_length : ' + str(len(article_list)))
for a in article_list:
html_response = HtmlResponse(uurl="", body=a.encode('utf-8') #??
seoul = html_response.xpath('//dl[@class="po_seoul"]//dd[@class="temp"]')[0].extract()
这是html代码
<h1 class="blind">weather_data</h1>
<div id="weather" class="weather" >
<dl class="po_seoul">
<dt>seoul</dt>
<dd class="weather"><a href="#" onclick="showLandForecast('1159068000'); return false;" data-stn="108"><img src="/images/icon/NW/NB04.png" alt="cloud" /></a></dd>
<dt class="blind">temperature</dt>
<dd class="temp">21.2</dd>
</dl>
天气数据
首尔
温度
21.2
错误消息:
seoul=html_response.xpath('//dl[@class=“po_seoul”]//dd[@class=“temp”]')[0].extract()
^
语法错误:无效语法
请帮助我…在HtmlResponse(uurl=“”,body=a.encode('utf-8')之后,您缺少)
HtmlResponse(uurl="", body=a.encode('utf-8'))
^
这一行中缺少了右括号,而不是你所拥有的。我刚刚修复了它,它工作了!谢谢你:D!