1

我试图潦草地写一个网页,但它的默认语言是意大利语,所以我需要将语言切换为英语。这是页面中的一段代码:

<td class="lang">
    [<a href="#" class="active" onclick="return SwitchLang('it')">ita</a> | 
    <a href="#" onclick="return SwitchLang('en')">eng</a>]
</td>

我尝试为此使用scrapy,我阅读了有关FormRequest.from_response 方法的信息,但我不知道我必须如何使用它。我尝试使用 formxpath。

我在蜘蛛中的一段代码是:

def parse(self, response):
    return [FormRequest.from_response(
                        response,                  
                        formxpath='/td[@class="lang"]/a[2]', 
                        dont_click=False, 
                        callback=self.after_lang_change)
                   ]

但它得到错误:

raise ValueError('No <form> element found with %s' % formxpath)
exceptions.ValueError: No <form> element found with /td[@class="lang"]/a[2]

我如何“点击”并更改语言?谢谢

4

0 回答 0