0

I am a newbie to python. I'm trying to crawl some text, but it doesn't work... Here is my code

    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()

and this is the html code.

            <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>

Error message:

seoul = html_response.xpath('//dl[@class="po_seoul"]//dd[@class="temp"]')[0].extract() ^ SyntaxError: invalid syntax

plz help me...T0T

2
  • html_response = HtmlResponse(uurl="", body=a.encode('utf-8') you are missing closing parentheses in this line. Commented Oct 5, 2017 at 9:10
  • i've just fixed it and it work! thank you :D! Commented Oct 5, 2017 at 9:16

1 Answer 1

1

You are missing ) after HtmlResponse(uurl="", body=a.encode('utf-8') it should be

HtmlResponse(uurl="", body=a.encode('utf-8'))
                                            ^

instead of what you have

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.