我正在尝试根据CSS属性在网页上提取特定的URL。我可以拉第一个,但我有困难获得完整的网址添加,或获得一个以上的网址。在
我尝试过使用joinurl或parse时遇到很多问题。joinurl不断出现全局错误。在
有没有更简单的方法??在
我使用的是Centos 6.5和Python 2.7.5
下面的代码将提供第一个URL,但不提供http://www...inline
import scrapy
class PdgaSpider(scrapy.Spider):
name = "pdgavideos" # Name of the Spider, required value
start_urls = ["http://www.pdga.com/videos/"]
# Entry point for the spiders
def parse(self, response):
SET_SELECTOR = 'tbody'
for brickset in response.css(SET_SELECTOR):
HTML_SELECTOR = 'td.views-field.views-field-title a ::attr(href)'
yield {
'http://www.pdga.com': brickset.css(HTML_SELECTOR).extract()[0]
}
电流输出
http://www.pdga.com
/视频/2017-glass-bould-open-fpo-rd-2-pt-2-pierce-fajkus-leatherman-c-allen-sexton-leatherman
预期输出
完整的url列表,没有任何分隔符
我没有足够的声誉点数来发布几个示例
你的代码返回一个字典,这就是为什么它是break:
你能做的就是把这个字典变成这样:
^{pr2}$这将给您一个新的dict值是no break href。在
注意:Spider必须返回Request、BaseItem、dict或None,引用parse function。在
为了从相对链接中获取绝对URL,可以使用Scrapyurljoin()方法,并按如下方式重写代码:
相关问题 更多 >
编程相关推荐