gpt4 book ai didi

python - scrapy 可以单独使用 scrapy 抓取 iframe 的内容吗?

转载 作者:行者123 更新时间:2023-11-28 16:37:18 27 4
gpt4 key购买 nike

iframe code

我已尝试复制并粘贴网站的元素 (xpath),但未返回任何结果。

scrapy 可以抓取 iframe 中的数据吗?如果是,如何做?如果不是,还应该做哪些其他事情?谢谢!

rules = (Rule (SgmlLinkExtractor(deny = path_deny_base, restrict_xpaths=('*'))
, callback="parse", follow= True),
)


def parse(self, response):
yield(Request(url, callback = self.parse_iframe))

def parse_iframe(self, response):
#your code to scrape the content from iframe
#def parse_items(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.select('//div[2]/h1')
#//div[2]/h1
linker = hxs.select('//div[2]/div[10]/a[1]')
#//div[2]/div[10]/a[1]
loc_Con = hxs.select('//div[2]/div[1]/div[2]/span/span/span[1]') #//div[2]/div[1]/div[2]/span/span/span[1]
loc_Reg = hxs.select('//div[2]/div[1]/div[2]/span/span/span[2]') #/div[2]/div[1]/div[2]/span/span/span[2]
loc_Loc = hxs.select('//div[2]/div[1]/div[2]/span/span/span[3]') #/div[2]/div[1]/div[2]/span/span/span[3]
items = []
for titles in titles:
item = CraigslistSampleItem()
#item ["job_id"] = id.select('text()').extract()[0].strip()
item ["title"] = map(unicode.strip, titles.select('text()').extract()) #ok
item ["link"] = linker.select('@href').extract() #ok
item ["info"] = (response.url)
temp1 = loc_Con.select('text()').extract()
temp2 = loc_Reg.select('text()').extract()
temp3 = loc_Loc.select('text()').extract()
temp1 = temp1[0] if temp1 else ""
temp2 = temp2[0] if temp2 else ""
temp3 = temp3[0] if temp3 else ""
item["code"] = "{0}-{1}-{2}".format(temp1, temp2, temp3)
items.append(item)
return(items)

最佳答案

Scrapy 无法从 iframe 中抓取内容。而是向 iframe URL 发出请求,例如:

def parse(self, response):
yield(Request(url, callback = self.parse_iframe))

def parse_iframe(self, response):
#your code to scrape the content from iframe

其中,url应该是iframe url,例如https://career-meridia....../jobs)

编辑:

用红色下划线部分替换url。 Put the underlined part编辑2:确保您已传递 iframe url 所需的每个参数。否则你将一无所获。如果是post方法,你必须传递所有的post参数。

关于python - scrapy 可以单独使用 scrapy 抓取 iframe 的内容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24301376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com