Web scraping 刮擦爬行蜘蛛规则-优先排序“;下页“; 我试着从旧金山的所有饭店名单中找出一个:
“下一家酒店”具有唯一的URL: 第2页是:/Hotels-g60713-oa30-San_Francisco_California-Hotels.html 第3页是:/Hotels-g60713-oa60-San\u Francisco\u California-Hotels.html 第4页是:/Hotels-g60713-oa90-San_Francisco_California-Hotels.html 等等Web scraping 刮擦爬行蜘蛛规则-优先排序“;下页“; 我试着从旧金山的所有饭店名单中找出一个: ,web-scraping,web-crawler,scrapy,Web Scraping,Web Crawler,Scrapy,“下一家酒店”具有唯一的URL: 第2页是:/Hotels-g60713-oa30-San_Francisco_California-Hotels.html 第3页是:/Hotels-g60713-oa60-San\u Francisco\u California-Hotels.html 第4页是:/Hotels-g60713-oa90-San_Francisco_California-Hotels.html 等等 如何设置爬行爬行器以到达这些页面 在这种情况下,有什么规则可以帮助我吗 有没有一
class TriAdvSpider(CrawlSpider):
name = "tripAdv"
allowed_domains = ["tripadvisor.com"]
start_urls = [
"http://www.tripadvisor.com/Hotels-g60713-San_Francisco_California-Hotels.html"
]
rules = (
Rule(SgmlLinkExtractor(allow=r'-\w+.html$'), callback='parse_item', follow=True),
)
def parse_item(self, response):
beatSoup_test.getHotels(response.body_as_unicode())
其中beatSoup\u test是我使用beautifulsoup的解析函数。
谢谢 如果您想从任何页面上刮取数据。使用 这样你们就可以在同一页上刮掉任何东西 并使用项目来存储刮取的数据,这样你就可以刮取你想要的任何东西 下面是您如何使用它的示例
sites = Selector(text=response.body).xpath('//div[contains(@id, "identity")]//section/div/div/h3/a/text()')
items = []
items = myspiderBotItem()
items['title'] = sites.xpath('/text()').extract()
像这样
class TriAdvSpider(CrawlSpider):
name = "tripAdv"
allowed_domains = ["tripadvisor.com"]
start_urls = [
"http://www.tripadvisor.com/Hotels-g60713-San_Francisco_California-Hotels.html"
]
rules = (
Rule(SgmlLinkExtractor(allow=r'-\w+.html$'), callback='parse_item', follow=True),
)
def parse_item(self, response):
# beatSoup_test.getHotels(response.body_as_unicode())
l = XPathItemLoader(item = TriAdvItem(),response = response)
for i in range(1,8):
l.add_xpath('day','//*[@id="super-container"]/div/div[1]/div[2]/div[2]/div[1]/table/tbody/tr['+str(i)+']/th[@scope="row"]/text()')
l.add_xpath('timings1','//*[@id="super-container"]/div/div[1]/div[2]/div[2]/div[1]/table/tbody/tr['+str(i)+']/td[1]/span[1]/text()')
l.add_xpath('timings2','//*[@id="super-container"]/div/div[1]/div[2]/div[2]/div[1]/table/tbody/tr['+str(i)+']/td[1]/span[2]/text()')
return l.load_item()